ssh不需要密码登陆配置
原理:
做法简单列举如下
1 客户端生成公钥私钥 ssh-keygen
[qixue@bogon ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/qixue/.ssh/id_rsa):
Created directory '/home/qixue/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/qixue/.ssh/id_rsa.
Your public key has been saved in /home/qixue/.ssh/id_rsa.pub.
The key fingerprint is:
80:0a:ad:6e:ed:7b:29:79:29:bd:01:fc:25:d8:93:b9 qixue@bogon
The key's randomart image is:
+--[ RSA 2048]----+
| |
| . . |
|. . . . |
| o..o o. |
|. .+ * .S |
|. . o = |
| o .oEo |
|. .+ *. |
| o*.. |
+-----------------+
[qixue@bogon .ssh]$ ls -al
total 16
drwx------. 2 qixue qixue 4096 May 13 00:24 .
drwx------. 23 qixue qixue 4096 May 13 00:24 ..
-rw-------. 1 qixue qixue 1675 May 13 00:24 id_rsa
-rw-r--r--. 1 qixue qixue 393 May 13 00:24 id_rsa.pub
2 客户端把公钥上传至服务器端~user/.ssh/目录下 其中.ssh目录要求是700 而pub公钥文件为644
[qixue@bogon .ssh]$ scp id_rsa.pub [email protected]:~/.ssh/
The authenticity of host '192.168.177.130 (192.168.177.130)' can't be established.
RSA key fingerprint is 68:6e:8d:17:9e:0e:8e:10:2c:81:2c:48:4d:a9:a0:75.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.177.130' (RSA) to the list of known hosts.
[email protected]'s password:
id_rsa.pub 100% 393 0.4KB/s 00:00
3 服务器端要做什么
[liuliancao@www .ssh]$ cat id_rsa.pub >> authorized_keys
[liuliancao@www .ssh]$ ls -l authorized_keys
-rw-rw-r--. 1 liuliancao liuliancao 393 May 7 18:00 authorized_keys
[liuliancao@www .ssh]$ chmod 644 authorized_keys
[liuliancao@www .ssh]$ ls -l authorized_keys
-rw-r--r--. 1 liuliancao liuliancao 393 May 7 18:00 authorized_keys
4 检验是否成功
[qixue@bogon .ssh]$ scp id_rsa [email protected]:~/.ssh/
id_rsa 100% 1675 1.6KB/s 00:00
已经成功
注意是对应的用户哦,如果是管理员则同理