這篇文章主要介紹了Linux下實現免密碼登入的相關資料,非常不錯,具有參考借鑒價值,有興趣的朋友一起看看吧
1.Linux下生成密鑰
ssh-keygen的命令手冊,透過」man ssh-keygen“命令:
# 通過命令” ssh-keygen -t rsa「
生成之後會在使用者的根目錄產生一個「.ssh」的資料夾
# 進入「.ssh」會產生以下幾個檔案
authorized_keys:存放遠端免密登入的公鑰,主要透過這個檔案記錄多台機器的公鑰
id_rsa : 產生的私鑰檔案
know_hosts : 已知的主機公鑰清單
如果希望ssh公鑰生效需滿足至少下面兩個條件:
) .ssh/authorized_keys檔案權限必須是6002.遠端免持登入
原理圖:
## 常用以下幾種方法:
2.1 透過ssh-copy-id的方式
指令:
ssh-copy-id -i ~/.ssh/id_rsa.put
[root@test .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.91.135 root@192.168.91.135's password: Now try logging into the machine, with "ssh '192.168.91.135'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [root@test .ssh]# ssh root@192.168.91.135 Last login: Mon Oct 10 01:25:49 2016 from 192.168.91.133 [root@localhost ~]#
# -bash: ssh-copy-id: command not found //提示指令不存在
解決方案:y#y 解決方案 opens-clilld open.透過scp將內容寫到對方的檔案中 指令:
scp -p ~/.ssh/id_rsa.pub root@
舉例:
###[root@test .ssh]# scp -p ~/.ssh/id_rsa.pub root@192.168.91.135:/root/.ssh/authorized_keys root@192.168.91.135's password: id_rsa.pub 100% 408 0.4KB/s 00:00 [root@test .ssh]# [root@test .ssh]# [root@test .ssh]# [root@test .ssh]# ssh root@192.168.91.135 Last login: Mon Oct 10 01:27:02 2016 from 192.168.91.133 [root@localhost ~]#
[root@test sshpass-1.05]# ansible test -m authorized_key -a "user=root key='{{ lookup('file','/root/.ssh/id_rsa.pub') }}'" -k SSH password: ----->输入密码 192.168.91.135 | success >> { "changed": true, "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArZI4kxlYuw7j1nt5ueIpTPWfGBJoZ8Mb02OJHR8yGW7A3izwT3/uhkK7RkaGavBbAlprp5bxp3i0TyNxa/apBQG5NiqhYO8YCuiGYGsQAGwZCBlNLF3gq1/18B6FV5moE/8yTbFA4dBQahdtVP PejLlSAbb5ZoGK8AtLlcRq49IENoXB99tnFVn3gMM0aX24ido1ZF9RfRWzfYF7bVsLsrIiMPmVNe5KaGL9kZ0svzoZ708yjWQQCEYWp0m+sODbtGPC34HMGAHjFlsC/SJffLuT/ug/hhCJUYeExHIkJF8OyvfC6DeF7ArI6zdKER7D8M0SM WQmpKUltj2nltuv3w== root@localhost.localdomain", "key_options": null, "keyfile": "/root/.ssh/authorized_keys", "manage_dir": true, "path": null, "state": "present", "unique": false, "user": "root" } [root@test sshpass-1.05]#
以上是Linux下實作免密碼登入(超詳細)的詳細內容。更多資訊請關注PHP中文網其他相關文章!