ユーザ用ツール

サイト用ツール


public:win10_openssh_en

文書の過去の版を表示しています。


OpenSSH In Windows 10

Connection settings for this article

Host NameLogin Name
ServerJump ServerJump Server Username
ClientLocalhostLocal Username

about PDF

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". スタートアップの種類は自動を選び, 開始を押し(プロパティ), ssh-agentサービスを起動する.
続いて, 秘密鍵 id_ecdsaを登録する.

PS C:\> ssh-add 'C:\Users\username\.ssh\id_ecdsa'
Enter passphrase for C:\Users\username\.ssh\id_ecdsa: # パスフレーズ入力
Identity added: C:\Users\username\.ssh\id_ecdsa (C:\Users\username\.ssh\id_ecdsa)

登録した鍵は, “ssh-add -l” で確認できる. もし登録した鍵を削除したい場合には “ssh-add -D” で削除する.

SSH接続

下記コマンドでssh接続する. -Aオプションは, 認証エージェントを転送する, つまりログインサーバに接続後, 続けて別のサーバに接続する際に, 最初に使った秘密鍵をそのまま使用するためにつける.

PS C:\> ssh 踏み台username@踏み台サーバ -A
The authenticity of host '踏み台サーバ (***.***.***.***)' 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 踏み台サーバ,***.***.***.***' (ECDSA) to the list of known hosts.

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 踏み台
public/win10_openssh_en.1657076599.txt.gz · 最終更新: 2022/07/06 12:03 by hirata.nanako

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki