linux下免密码证书登入设置&遇到问题解决办法
1、远程:192.168.1.11
2、本地:192.168.1.10
步骤
1、创建密钥
1
ssh-keygen -t rsa
luoyangbo@localhost:~/.ssh$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): (忽略)
Enter same passphrase again: (忽略)
Your identification has been saved in /home/luoyangbo/.ssh/id_rsa.
Your public key has been saved in /home/luoyangbo/.ssh/id_rsa.pub.
2、复制公密到服务器
1
scp id_rsa.pub [email]luoyangbo@192.168.1.11[/email]:/home/luoyangbo/.ssh/192.168.1.10
luoyangbo@localhost:~/.ssh$ scp id_rsa.pub [email]miao@192.168.1.112[/email]:/home/luoyangbo/.ssh/192.168.1.11
[email]luoyangbo@192.168.1.11[/email]'s password:
id_rsa.pub 100% 404 0.4KB/s 00:00
3、添加公密到192.168.11的信任区域
1
cat 192.168.1.10 >> authorized_keys
注: 2,3两步可由命令ssh-copy-id一步到位
1
ssh-copy-id [email]luoyangbo@192.168.1.11[/email]
luoyangbo@localhost:~/.ssh$ ssh-copy-id [email]luoyangbo@192.168.1.11[/email]
Password:
Now try logging into the machine, with "ssh 'luoyangbo@192.168.1.11'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
4、启动ssh-agent
如果ssh 192.168.11返回 Agent admitted failure to sign using the key
ps -Af | grep agent查看有无ssh-agent有无运行,若没有
luoyangbo@localhost:~/.ssh$ ssh-agent
5、添加id_rsa到ssh-agent
luoyangbo@localhost:~/.ssh$ ssh-add id_rsa
PS:遇到问题&解决办法
一切完成后,ssh远程仍然需要密码验证。
这时只需要修改远程机器.ssh及其下面文件的权限即可
1
2
3
4
chown username: /home/username/.ssh
chown username: /home/username/.ssh/*
chmod 700 /home/username/.ssh
chmod 600 /home/username/.ssh/*