LoginSignup
5
1

More than 3 years have passed since last update.

Windows10 で SSH ができるらしい

Last updated at Posted at 2019-12-02

この記事はSRA Advent Calendar 2019の3日目の記事です。

はじめて記事をかいてみます。NETS1の田中Tです。

Windows10 で SSH ができるようになったらしい!

Windows10 で SSH ができるようになったらしいです。
といっても2018年4月からデフォルトで OpenSSH のクライアントが導入されていたみたいです。
ここ最近作業端末が Windows10 になったもので、最近知りました。

というわけで兎にも角にもとりあえずやってみよう!

やってみた

コマンドプロンプトを立ち上げて、SSHしてみました。

C:\Users\t-tanaka>ssh xxx.xxx.xxx.xxx
The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established.
RSA key fingerprint is SHA256:yKlsrXenrqmhIUhJcj7SF87MBS/tpUVGQQteXFaeqFL.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'xxx.xxx.xxx.xxx' (RSA) to the list of known hosts.
t-tanaka@xxx.xxx.xxx.xxx's password:
Last login: Mon Dec  2 18:53:56 2019 from yyy.yyy.yyy.yyy
[t-tanaka@hoge ~]$

(一応IPは伏せときます。)

なんか感動。

気になる

とりあえずできたけど、known_hosts の場所とか、config が使えるのかとか鍵認証ができるのかとか、いろいろ気になる!
OpenSSH が入っているんだからできるんだろうけども!!!
ドキュメントとか調べるのも面倒だし、-v オプションを実行してみることに。

C:\Users\t-tanaka>ssh -v xxx.xxx.xxx.xxx
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1: Connecting to xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
... 略 ...
debug1: Found key in C:\\Users\\t-tanaka/.ssh/known_hosts:1
... 略 ...
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: C:\\Users\\t-tanaka/.ssh/id_rsa
debug1: Trying private key: C:\\Users\\t-tanaka/.ssh/id_dsa
debug1: Trying private key: C:\\Users\\t-tanaka/.ssh/id_ecdsa
debug1: Trying private key: C:\\Users\\t-tanaka/.ssh/id_ed25519
debug1: Trying private key: C:\\Users\\t-tanaka/.ssh/id_xmss
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such file or directory
t-tanaka@xxx.xxx.xxx.xxx's password:

C:\Users\t-tanaka>

なんだかユーザーのホームディレクトリに .ssh があるらしい。
そして鍵認証もできそう。

じゃあやってみよう

1. 秘密鍵を作る(ssh-keygen コマンドもあるみたい。)

C:\Users\t-tanaka>ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\t-tanaka/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\t-tanaka/.ssh/id_rsa.
Your public key has been saved in C:\Users\t-tanaka/.ssh/id_rsa.pub.
The key fingerprint is:
... 略 ...

2. 作成された公開鍵 id_rsa.pub の中身を接続先の authorized_keys に加える。
3. こんな感じの config ファイルを作って .ssh 以下に置く。

Host hoge
        HostName xxx.xxx.xxx.xxx
        User t-tanaka
        IdentityFile ~/.ssh/id_rsa

4. ssh hoge でアクセス!

C:\Users\t-tanaka>ssh hoge
Enter passphrase for key 'C:\Users\t-tanaka/.ssh/id_rsa':
Last login: Mon Dec  2 22:36:49 2019 from yyy.yyy.yyy.yyy
[t-tanaka@hoge ~]$

できた!
というかホームディレクトリの指定は ~ でいいんだ・・・。

ほかにできること

where ssh で調べてみると、実行ファイルはC:\Windows\System32\OpenSSHにあるみたいです。

C:\Users\t-tanaka>dir C:\Windows\System32\OpenSSH
 ドライブ C のボリューム ラベルは Windows です
 ボリューム シリアル番号は FCCA-5338 です

 C:\Windows\System32\OpenSSH のディレクトリ

2019/03/19  21:30    <DIR>          .
2019/03/19  21:30    <DIR>          ..
2019/03/19  21:30           322,560 scp.exe
2019/03/19  21:30           390,144 sftp.exe
2019/03/19  21:30           491,520 ssh-add.exe
2019/03/19  21:30           384,512 ssh-agent.exe
2019/03/19  21:30           637,952 ssh-keygen.exe
2019/03/19  21:30           530,432 ssh-keyscan.exe
2019/03/19  21:30           882,688 ssh.exe
               7 個のファイル           3,639,808 バイト
               2 個のディレクトリ  164,764,667,904 バイトの空き領域

C:\Users\t-tanaka>

見た感じ、scp, sftp, ssh-agent などなど一通りの機能はつかえそうですね。

最後に

じゃあ今後使っていくのかというと、業務上の都合で基本的に全セッションのログを記録しておく必要があるので、
あまり使う機会がなさそうです。(普段は PuTTY をつかってます。)
ただ、SCP は WinSCP をわざわざ導入する必要もなくなるので使っていきたい感じです。

みなさんも使ってみてはいかがでしょうか。

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1