ssh-免密钥登录

制作密钥对

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# ssh-keygen -t dsa  ##创建密钥对使用dsa加密
Generating public/private dsa key pair.
Enter file in which to save the key (/niu/.ssh/id_dsa): ##指定key存放位置,可以直接回车。
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): ##输入密钥锁,可以直接回车。
Enter same passphrase again:
Your identification has been saved in /niu/.ssh/id_dsa.
Your public key has been saved in /niu/.ssh/id_dsa.pub.
The key fingerprint is:
64:47:0d:9c:ab:8f:1e:7e:5a:b0:25:64:55:23:06:3a niu@centos6.7-mupan
The key's randomart image is:
+--[ DSA 1024]----+
| .o*=o |
| . +o... |
| E = .. |
| * .. |
| S.. |
| .= |
| oo. |
| ..oo |
| .+o |
+-----------------+

在服务器上安装公钥并设置权限

1
2
3
4
cd .ssh/
cat id_dsa.pub >> authorized_keys
chmod 600 authorized_keys
chmod 700 ~/.ssh

编辑/etc/ssh/sshd_config启用密钥登录

1
2
RSAAuthentication yes
PubkeyAuthentication yes

将公钥下载到客户端,然后使用公钥登录