サーバー
IPアドレス 192.168.0.1
クライアント
IPアドレス 192.168.0.2
クライアント作業
IPアドレス 192.168.0.1
[taro@localhost toshi]$ cat /etc/vine-release Vine Linux 4.2 (Lynch Bages) [taro@localhost toshi]$ ssh -V OpenSSH_4.5p1, OpenSSL 0.9.7l 28 Sep 2006のtaroアカウントホームディレクトリのファイル address.txt を
クライアント
IPアドレス 192.168.0.2
[taro@deskpro ~]$ cat /etc/vine-release Vine Linux 5.1 (Cheval Blanc) [taro@deskpro ~]$ ssh -V OpenSSH_5.2p1, OpenSSL 0.9.8k 25 Mar 2009のカレントディレクトリへ暗号化された経路で転送。
scp user@192.168.0.1:address.txt .バッチ準備編よりも簡単な手法。
クライアント作業
[taro@localhost ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/taro/.ssh/id_rsa):空でエンター Created directory '/home/taro/.ssh'. Enter passphrase (empty for no passphrase):空でエンター Enter same passphrase again:空でエンター Your identification has been saved in /home/taro/.ssh/id_rsa. Your public key has been saved in /home/taro/.ssh/id_rsa.pub. The key fingerprint is: c5:d2:7a:31:7a:58:d3:cf:a5:7f:8f:48:16:0a:f9:3e taro@client The key's randomart image is: +--[ RSA 2048]----+ | | | o . | | . O . .| | O + o o | | S o . + | | = . . . | | o o o| | .Eo . .o| | ... . .| +-----------------+
[taro@localhost taro]$ scp ~/.ssh/id_rsa.pub taro@192.168.0.1:~/.ssh/authorized_keys taro@192.168.0.1's password: id_rsa.pub 100% 395 0.4KB/s 00:00パスワード省略したい接続元が複数ある場合は、サーバーの ~/.ssh/authorized_keys へ追記する これだけで終わり。以降、サーバー側の~/.ssh/authorized_keys にクライアントの公開鍵 ~/.ssh/id_rsa.pub が含まれている限りバッチなどでパスワードを省略可能。
[taro@localhost taro]$ scp taro@192.168.0.1:address.txt . address.txt 100% 1743 1.7KB/s 00:00下記は、技術的なメモ。
サーバ側必須要件(下記)が満たされていないとパスワード要求される
●ホームディレクトリのパーミッション
●.shosts の存在は無関係。
●/etc/ssh/sshd_config はデフォルトのまま。
●ホームディレクトリのパーミッション
drwxrwxr-x 775 × drwxr-xr-x 755 ○ drwx--x--x 711 ○ drwx------ 755 ○●~/.sshディレクトリのパーミッション
drw------- 600 × drwx------ 700 ○●~/.ssh/authorized_keysファイルのパーミッション
-rw------- 600 ○●接続先のホスト名とIPアドレス違いは無関係。
●.shosts の存在は無関係。
●/etc/ssh/sshd_config はデフォルトのまま。
[root@server ~]# cat /etc/ssh/sshd_config | grep AuthorizedKeysFile #AuthorizedKeysFile .ssh/authorized_keys●上記を相互に設定すれば、どちらからもパスフレーズ・パスワード省略可能。 ●クライアント・サーバーともに
[taro@localhost ~]$ cat /etc/redhat-release CentOS release 5.5 (Final) [taro@localhost ~]$ ssh -V OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008でも確認済み