文書の過去の版を表示しています。
目次
OpenSSH In Windows 10
Connection settings for this article
Host Name | Login Name | |
---|---|---|
Server | Jump Server | Jump Server Username |
Client | Localhost | Local Username |
Open PowerShell
Press Start and then press “Windows PowerShell”.
How do I know if OpenSSH is installed?
Check if the OpenSSH client is installed by typing the following command into PowerShell.
PS C:\> gcm ssh | fl Name : ssh.exe CommandType : Application Definition : C:\WINDOWS\System32\OpenSSH\ssh.exe Extension : .exe Path : C:\WINDOWS\System32\OpenSSH\ssh.exe FileVersionInfo : File: C:\WINDOWS\System32\OpenSSH\ssh.exe InternalName: OriginalFilename: FileVersion: 7.7.2.1 ...
If the details of ssh.exe are displayed as above, it has been installed.
If you do not see it, Windows Update (version 1803 or later) with administrator privileges will install the OpenSSH client by default. If not, open Settings, select Apps > Apps & Features, then select "Optional Features" .
Generate an SSH Key Pair
Generate an ssh key in PowerShell. (After # are comments)
PS C:\> ssh-keygen -t ecdsa -b 384 Generating public/private ecdsa key pair. Enter file in which to save the key (C:\Users\username\.ssh\id_ecdsa): # enter Enter passphrase (empty for no passphrase): #Enter passphrase Enter same passphrase again: #Enter passphrase Your identification has been saved in test. Your public key has been saved in test.pub. The key fingerprint is: SHA256:UQwYcMTRGPdEDwQ7y4z5OS+j9PhFpavrKZ3W7jEuH1E username@localhost The key's randomart image is: +---[ECDSA 384]---+ | .+*B+** | | .+..=.o | | + . E | | = + + | | o S + | | . o o | | ..+o* | | ..oBB.+ | | o*BO* | +----[SHA256]-----+
Key pairs are created in the (C:\Users\username\.ssh\id_ecdsa) by default. The key may not be used unless it is placed in a folder under the user.
Apply for a key
Please apply for registration of the created public key id_ecdsa.pub.
isee Jump Server account request
CIDAS System account request
Add your SSH key to the ssh-agent
Use ssh-agent to avoid entering the passphrase for ssh connections and to avoid putting the private key on the steppingstone server.
Select Start > Administrative Tools > Services. Open the properties of the "OpenSSH Authentication Agent". Select automatic as the startup type, press start, and start the ssh-agent service (properties).
Next, register the private key id_ecdsa.
PS C:\> ssh-add 'C:\Users\username\.ssh\id_ecdsa' Enter passphrase for C:\Users\username\.ssh\id_ecdsa: #Enter passphrase Identity added: C:\Users\username\.ssh\id_ecdsa (C:\Users\username\.ssh\id_ecdsa)
The registered key can be checked with “ssh-add -l”. If you want to delete a registered key, use “ssh-add -D” to do so.
SSH Connection
Enter the following:
PS C:\> ssh Jump Server Username@Jump Server -A The authenticity of host 'Jump Server (***.***.***.***)' can't be established. ECDSA key fingerprint is SHA256:UQwYcMTRGPdEDwQ7y4z5OS+j9PhFpavrKZ3W7jEuH1E. Are you sure you want to continue connecting (yes/no)? # yes Warning: Permanently added Jump Server,***.***.***.***' (ECDSA) to the list of known hosts.
option -A: Enables forwarding of connections from an authentication agent such as ssh-agent.
After connecting to the Jump Server, you can use the same private key that you used at the first connection to connect to another server.
X転送
リモート接続時に X Window System (X11) を転送して, xアプリケーションウィンドウをローカルホストで利用する.
まず, VcXsrv Windows X Server をダウンロードし, インストールする.
VcXsrv ダウンロード
起動画面ではデフォルトで進み, 最後の"finish configuration" 画面で, “save configuration”を押し, 適当な場所に設定を保存する (設定ファイルのデフォルト名は config.xlaunch).
設定ファイルをダブルクリックすることで, VcXsrv Windows X Server が起動するようになるが, 自動起動させるために, スタートアップに登録する.
“スタート” → “Windows システムツール” →"ファイル名を指定して実行"で, shell:startup と打ち, スタートアップのフォルダを開く. さきほど保存した設定ファイル config.xlaunch をスタートアップフォルダに移動する.
次に, 環境変数DISPLAYを設定する. VcXsrv Windows X Server が起動しているとインジケーターにアイコンが表示されるが, アイコンの上にマウスを乗せると “localhost:0.0 -1 clients” のように表示されるので, この localhost:0.0 を環境変数DISPLAYに設定する. ここでの locaohost 部分は, ローカルのホストネーム, 127.0.0.1, localhost のいずれでもよい.
PS C:\ [System.Environment]::SetEnvironmentVariable("DISPLAY", "localhost:0.0", "User")
PS を再起動し, 設定されているか確認する.
PS C:\ $env:DISPLAY localhost:0.0
x転送を許可するオプションを追加し, ssh接続する. xアプリケーションを起動し, 転送できているかを確認する.
PS C:\ ssh -AXY 踏み台username@踏み台サーバ
ssh接続設定のファイル
以上の設定をファイルに保存し (C:\Users\username\.ssh\config), sshコマンドを省略できる.
* IdentityFile は秘密鍵を ssh-agent に登録するため必要ないが, 記録のため記述しておくとよい.
Host 踏み台 ForwardAgent yes ForwardX11 yes ForwardX11Trusted yes User 踏み台username HostName 踏み台サーバ IdentityFile "C:\Users\username\.ssh\id_ecdsa"
下記コマンドでssh接続できる.
PS C:\ ssh 踏み台