Home | Mirror | Search |
config /etc/ssh/sshd_config
$ sudo vim /etc/ssh/sshd_config AuthorizedKeysFile %h/.ssh/authorized_keys $ sudo /etc/init.d/ssh reload
ssh-keygen
ssh-keygen -dmaster server
[netkiller@master ~]$ ssh-keygen -d Generating public/private dsa key pair. Enter file in which to save the key (/home/netkiller/.ssh/id_dsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/netkiller/.ssh/id_dsa. Your public key has been saved in /home/netkiller/.ssh/id_dsa.pub. The key fingerprint is: bf:a9:21:2c:82:77:2d:71:33:12:20:10:93:5f:cb:74 netkiller@master [netkiller@master ~]$ [netkiller@master ~]$ cp .ssh/id_dsa.pub .ssh/authorized_keys [netkiller@master ~]$ chmod 600 .ssh/authorized_keys [netkiller@master ~]$ ls -l .ssh/ total 12 -rw------- 1 netkiller netkiller 612 Mar 27 15:31 authorized_keys -rw------- 1 netkiller netkiller 736 Mar 27 15:24 id_dsa -rw-r--r-- 1 netkiller netkiller 612 Mar 27 15:24 id_dsa.pub [netkiller@master ~]$
backup server
[netkiller@backup ~]$ ssh-keygen -d Generating public/private dsa key pair. Enter file in which to save the key (/home/netkiller/.ssh/id_dsa): Created directory '/home/netkiller/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/netkiller/.ssh/id_dsa. Your public key has been saved in /home/netkiller/.ssh/id_dsa.pub. The key fingerprint is: c5:2f:0e:4e:b0:46:47:ec:19:30:be:9c:20:ad:9c:51 netkiller@backup [netkiller@backup ~]$ cp .ssh/id_dsa.pub .ssh/authorized_keys [netkiller@backup ~]$ chmod 600 .ssh/authorized_keys [netkiller@backup ~]$ ls -l .ssh/ total 16 -rw------- 1 netkiller netkiller 609 Mar 27 15:31 authorized_keys -rw------- 1 netkiller netkiller 736 Mar 27 15:27 id_dsa -rw-r--r-- 1 netkiller netkiller 609 Mar 27 15:27 id_dsa.pub
交換公鑰證書
master => backup
[netkiller@master ~]$ scp .ssh/id_dsa.pub netkiller@backup.example.org:.ssh/master.pub netkiller@backup.example.org's password: id_dsa.p 100% 612 0.6KB/s 00:00 [netkiller@master ~]$ [netkiller@backup ~]$ cat .ssh/master.pub >> .ssh/authorized_keys
test
[netkiller@master ~]$ ssh backup.example.org Enter passphrase for key '/home/netkiller/.ssh/id_dsa': Last login: Tue Mar 27 15:26:35 2007 from master.example.org [netkiller@backup ~]$
master <= backup
[netkiller@backup ~]$ scp .ssh/id_dsa.pub netkiller@master.example.org:.ssh/backup.pub netkiller@master.example.org's password: id_dsa.pub 100% 609 0.6KB/s 00:00 [netkiller@backup ~]$ [netkiller@master ~]$ cat .ssh/backup.pub >> .ssh/authorized_keys
test
[netkiller@backup ~]$ ssh master.example.org Enter passphrase for key '/home/netkiller/.ssh/id_dsa': Last login: Tue Mar 27 15:44:37 2007 from backup.example.org [netkiller@master ~]$
注意:authorized_keys權限必須為600,否則可能登陸的時候還會讓你輸入密碼,但是一旦改成600以後並且成功登陸,此問題不再出現。
script
ssh-keygen -d cp .ssh/id_dsa.pub .ssh/authorized_keys chmod 600 .ssh/authorized_keys ls -l .ssh/