SSH

Debianインストール後、SSHを設定する方法

参考: << www.linux.net-japan.info/install04.html >>

SSHサーバの設定

sshd_configの設定
/etc/ssh/sshd_configファイルを設定する。
設定方針:指定したユーザのみが、SSHサーバに接続できるように設定する。

vim /etc/ssh/sshd_config

PermitRootLogin no
AuthorizedKeyFile %h/ .ssh/authorized_keys

DenyUsers ALL
AllowUsers etch taro hanako

2) TcpWrapperの設定

/etc/hosts.allowと/etc/hosts.denyファイルで、SSH接続できるネットワーク又はIPアドレスを指定する。
TCPのパッケと段階でもアクセス制限を行う。この場合は、内部のプライベートネットワークからの接続を許可している。

vim /etc/hosts.allow

ALL: 127.0.0.1
sshd: 192.168.1.

vim /etc/hosts.deny
sshd: ALL

3) sshd_configの設定変更を有効にする

/etc/init.d/ssh restart

 

SSH(公開鍵と秘密鍵の作成)

ssh-keygen -t rsa  を実行します。

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/xxxxx/.ssh/id_rsa): 
/Users/xxxxx/.ssh/id_rsa already exists.
Overwrite (y/n)? yes
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/xxxxx/.ssh/id_rsa.
Your public key has been saved in /Users/xxxxx/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Dqvvyxxxxxxxxxxxxx xxxxx@iMac27.local
The key's randomart image is:
+---[RSA 2048]----+
|       .o   . .  |
|       o.=.xxxxxxx
|      oxxxxxxxxx
|       xxxxxxxx
| . .  xxxxxxxxxxxx
|. . ...=+ . ... .|
|. . ..xxxxxxxxxxxxx
| . . o o  .      |
|    .xxxxxxxxxxxx
+----[SHA256]-----+

 

よくある現象

 

SSH接続時に以下のようなエラーが出た時

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:wASxKs7rxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx
Please contact your system administrator.
Add correct host key in /Users/xxxxxxx/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/xxxxxxx/.ssh/known_hosts:4
RSA host key for 192.168.0.8 has changed and you have requested strict checking.
Host key verification failed.

このワーニングの原因は、接続先ホストを再インストールしたり、SSHサーバーの設定が変更になった場合などで接続できない状態になっているからです。

一つの方法として、known_hosts の設定情報を削除する方法です。 ssh-keygen -R 接続ホスト名

ssh-keygen -R 192.168.0.8
# Host 192.168.0.8 found: line 4
/Users/xxxxx/.ssh/known_hosts updated.
Original contents retained as /Users/xxxxx.ssh/known_hosts.old

SSH接続の確認

ssh hodota$ ssh -l hodota 192.168.0.8
The authenticity of host '192.168.0.8 (192.168.0.8)' can't be established.
ECDSA key fingerprint is SHAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.8' (ECDSA) to the list of known hosts.
xxxxx@192.168.0.8's password: 

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Jan 17 12:08:21 2016 from xxxxxxxx.xxxxxxx

 

詳細はここを参考に

 

オープンソースソフトウェア: