ssh無密碼登入設置

現有2臺機器

1、服務器192.168.1.112

2、個人機192.168.1.110

要使110無需密碼通過ssh登入112

步驟

1、創建密鑰

miao@u32-192-168-1-110:~/.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/miao/.ssh/id_rsa.
Your public key has been saved in /home/miao/.ssh/id_rsa.pub.

2、複製公密到服務器

miao@u32-192-168-1-110:~/.ssh$ scp id_rsa.pub [email protected]:/home/miao/.ssh/192.168.1.110
[email protected]'s password: 
id_rsa.pub                                                                   100%  404     0.4KB/s   00:00    
miao@u32-192-168-1-110:~/.ssh$ 

3、添加公密到192.168.112的信任區域

miao@debian-192-168-1-112:~/.ssh$ cat 192.168.1.110 >> authorized_keys
miao@debian-192-168-1-112:~/.ssh$ 

注: 2,3兩步可由命令ssh-copy-id一步到位

miao@ubuntu-192-168-1-110:~/.ssh$ ssh-copy-id [email protected]
Password:
Now try logging into the machine, with "ssh '[email protected]'", 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.112返回 Agent admitted failure to sign using the key
ps -Af|grep agent查看有無ssh-agent有無運行,若沒有

miao@u32-192-168-1-110:~/.ssh$ ssh-agent

5、添加id_rsa到ssh-agent

miao@u32-192-168-1-110:~/.ssh$ ssh-add id_rsa

6、完成


作者鏈接:http://www.jiangmiao.org/blog/559.html


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章