LoginSignup
1
1

More than 3 years have passed since last update.

Windows Server から CygwinでSSHしてみる

Last updated at Posted at 2020-11-08

はじめに

Windows Serverを煮え湯を飲んで触らなくてはいけない状況になり、いきなり会社の環境を触るわけにもいかないので家で疑似的にいろいろすることにしました。「Cygwinでできるよ!」って確認だけなんで、中身的には普通のSSH接続です。

Windows Serverで鍵作成

Windows Server(180日の評価版)とCygwin導入は他所でもよく書かれてますので省略。VirtualBox上にWindows Server 2016を導入。Cygwinと、openSSHも導入済みからスタートです。
Cygwinからssy-keygenして普通に鍵を作ります。

Administrator@WIN
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/Administrator/.ssh/id_rsa):
Created directory '/home/Administrator/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/Administrator/.ssh/id_rsa
Your public key has been saved in /home/Administrator/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:2ZULZIXXXXXXXXXXXXXXXXXXXZUeSgeK/XXXXXXXXX Administrator@WIN
The key's randomart image is:
+---[RSA 3072]----+
|      .o .o      |
|    きらきら星    |
|o=o+*==+         |
+----[SHA256]-----+

Linuxでやるのと同じですね。どうせ社内なんでパスフレーズ無にしました。公開鍵を確認してみます。

Administrator@WIN  ~/.ssh
$ ls -ltr
合計 5
-rw------- 1 Administrator なし 2622 11月  7 18:28 id_rsa
-rw-r--r-- 1 Administrator なし  583 11月  7 18:28 id_rsa.pub
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1(省略・・・というかナイショ)Hc= Administrator@WIN 

接続先のUbuntuで公開鍵の登録

接続先ユーザーとして sshuser を作成し、authorized_keys にCygwinで作成した公開鍵を登録します。

sshuser@LarkBox:~/.ssh$ touch authorized_keys
sshuser@LarkBox:~/.ssh$ vi authorized_keys
sshuser@LarkBox:~/.ssh$
sshuser@LarkBox:~/.ssh$ cat authorized_keys
ssh-rsa AAAAB3NzaC1(省略・・・というかナイショ)Hc= Administrator@WIN

Windows ServerからUbuntuへ接続

ssh -l (接続ユーザー) -i (秘密鍵の場所) (接続先IP)

Administrator@WIN  ~/.ssh
$ ssh -l sshuser -i /home/Administrator/.ssh/id_rsa (UbuntuのIPアドレス)
The authenticity of host '(UbuntuのIPアドレス)' can't be established.
ECDSA key fingerprint is SHA256:(フィンガープリント)

繋いでいいかい?って問われるのでYesとする。

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '(UbuntuのIPアドレス)' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-52-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

110 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable

Your Hardware Enablement Stack (HWE) is supported until April 2025.
Last login: Sat Nov  7 19:34:37 2020 from 接続元IPアドレス
sshuser@LarkBox:~$ whoami
sshuser
sshuser@LarkBox:~$
sshuser@LarkBox:~$ exit
ログアウト
Connection to UbuntuのIPアドレス closed.

念のためknown_hostsを確認する。

Administrator@WIN  ~/.ssh
$ cat known_hosts
(UbuntuのIPアドレス) ecdsa-sha2-nistp256 AAAAE2VjZ(省略)dJxwi8mk=

まとめ

ということで(?)、Cygwinを使ってLinux(Ubuntu)にsshできる事がわかりました。次はこれを使ってファイルのやり取りをどうやるかですね。

1
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
1
1