添加使用者:
useradd yang
生成秘鑰
[yang@localhost /]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key(/home/yang/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):123456
Enter same passphrase again: 123456
Your identification has been saved in/home/yang/.ssh/id_rsa.
Your public key has been saved in/home/yang/.ssh/id_rsa.pub.
The key fingerprint is:
1d:1d:97:0c:c0:40:8f:a4:1a:b9:93:71:03:7a:d4:[email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| o. .+o..oo.. |
| oo.o o.. oo |
| .=.+ . o . |
| ..B . . . |
| =. S . |
| E. |
| |
+-----------------+
修改權限:
[root@localhost yang]# chmod 700 .ssh
[root@localhost yang]# cd .ssh
[root@localhost .ssh]# ll
總用量 8
-rw------- 1 yang yang 1743 7月 14 03:22 id_rsa
-rw-r--r-- 1 yang yang 408 7月 14 03:22 id_rsa.pub
[root@localhost .ssh]# mv id_rsa.pubauthorized_keys
[root@localhost .ssh]# chmod 600authorized_keys
将私鑰拷貝出來
<a href="http://s3.51cto.com/wyfs02/M00/6F/A5/wKiom1WjpInym1bkAAPQdNTA1Gs435.jpg" target="_blank"></a>
修改ssh配置檔案
Vim /etc/ssh/sshd_config
42: PermitRootLogin no #禁止root登陸
47:RSAAuthentication yes #RSA驗證
48:PubkeyAuthentication yes #公鑰驗證
49: AuthorizedKeysFile .ssh/authorized_keys #加載秘鑰
66: PasswordAuthentication no #禁止密碼登入
重新開機ssh
Service sshd restart
Xshell登入
<a href="http://s3.51cto.com/wyfs02/M00/6F/A5/wKiom1WjpIny-LqBAAFssAQdT_Q736.jpg" target="_blank"></a>
導入剛拷貝的私鑰
<a href="http://s3.51cto.com/wyfs02/M01/6F/A2/wKioL1WjpmCQKlKSAAF9ixQjj5k797.jpg" target="_blank"></a>
輸入密碼登入
<a href="http://s3.51cto.com/wyfs02/M01/6F/A2/wKioL1WjpmGQibdwAADzKHpV29g547.jpg" target="_blank"></a>
本文轉自2013yang 51CTO部落格,原文連結:http://blog.51cto.com/yangeinstein/1673886,如需轉載請自行聯系原作者