OPENSSH

sshアクセスに公開鍵認証を設定

  • 公開鍵・秘密鍵生成
[hiro@localhost ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hiro/.ssh/id_rsa):
Created directory '/home/hiro/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hiro/.ssh/id_rsa.
Your public key has been saved in /home/hiro/.ssh/id_rsa.pub.
The key fingerprint is:
  • 生成ファイル
[hiro@localhost ~]$ ls -l /home/hiro/.ssh
-rw------- 1 hiro hiro 1743  4月 29 18:48 id_rsa
-rw-r--r-- 1 hiro hiro  408  4月 29 18:48 id_rsa.pub
秘密鍵→id_rsa
公開鍵→id_rsa.pub
  • パスワードなしのsshログインを行う
[hiro@localhost ~]$ cd /home/hiro/.ssh
[hiro@localhost .ssh]$ mv id_rsa.pub authorized_keys
[hiro@localhost .ssh]$ chmod 600 authorized_keys
  • "id_rsa"をローカル転送
winSCPを使って安全に転送
ダウンロード:http://winscp.net/eng/download.php#download2
※id_rsaは秘密鍵なので誰にも知られないように保管
  • "PuTTY"を使用しているので、"PuTTYgen"を使ってサーバで生成した秘密鍵をPuTTYで使用できるようにする。

パスワードログイン禁止

[root@localhost ~]# vi /etc/ssh/sshd_config
PermitEmptyPasswords no
PasswordAuthentication no
[root@localhost ~]# /etc/init.d/sshd restart
sshd を停止中:                                             [  OK  ]
sshd を起動中:                                             [  OK  ]

確認

login as: hiro
Authenticating with public key "imported-openssh-key"
Passphrase for key "imported-openssh-key":

タグ:

ssl
最終更新:2010年04月30日 02:54
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。