從主機A得到id_rsa.pub文件,在主機B創建用戶danny加入該文件,實現主機A免密登錄主機B
阿新 • • 發佈:2018-08-31
ann roo 1.2 test dir public 創建用戶 需要 phrase
操作步驟:
1.主機A
生成公鑰id_rsa.pub文件並導出該文件
root@mytest:~# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been savedin /root/.ssh/id_rsa.pub. The key fingerprint is: 7e:0f:dc:05:2e:d3:e0:24:c0:5f:fe:cf:e9:7a:f7:49 root@mytest The key‘s randomart image is: +--[ RSA 2048]----+ | .. | | .. . | | ..oo . | | .+.+ . | | S +.o . | | . . +.. | | . + .o E | | . o * o| | o+.oo| +-----------------+ root@mytest:~# sz /root/.ssh/id_rsa.pub
這步之後也可以通過以下步驟直接實現公鑰認證(但是需要知道主機B用戶danny的密碼)
# ssh-copy-id -i /root/.ssh/id_rsa.pub danny@12.1.1.2 danny@12.1.1.2‘s password: //輸入主機B用戶danny的登錄密碼
2.主機B
得到id_rsa.pub文件,創建用戶danny,並在該用戶家目錄創建.ssh文件夾和其文件下的遠程認證文件authorized_keys
[root@B danny]# mkdir .ssh [root@B danny]# cd .ssh/ [root@B .ssh]# touch authorized_keys [root@B .ssh]# ls authorized_keys [root@B .ssh]# cat /home/danny/id_rsa.pub >authorized_keys
主機A登錄主機B
root@mytest:/# ssh danny@IP_B
從主機A得到id_rsa.pub文件,在主機B創建用戶danny加入該文件,實現主機A免密登錄主機B