解決:centos配置ssh免密碼登入後仍要輸入密碼

來源:互聯網
上載者:User

標籤:with   password   author   art   複製粘貼   lin   ref   you   zhang   

轉自https://www.jb51.net/article/121180.htm

 

第一步:在本機中建立秘鑰

1、執行命令:ssh-keygen -t rsa 

2、之後一路斷行符號就行啦;會在~(home)目錄下中產生.ssh(隱藏)檔案夾;

3、裡面有兩個檔案id_rsa(私密金鑰)、id_rsa.pub(公開金鑰)檔案

注意事項:

①在liunx環境下,要想複製公開金鑰或是私密金鑰,不要使用vim等編輯器開啟檔案來複製粘貼;

因為它會產生不必要的斷行符號。

②應該使用cat把內容列印到終端上再來複製粘貼;

第二步:用 ssh-copy-id 把公開金鑰複製到遠程主機上

ssh-copy-id [email protected]192.168.161.132

把秘鑰拷貝到遠程伺服器

用這種方式拷貝使用的連接埠是Linux預設的22,如果你想指定連接埠,可以使用:

ssh-copy-id -i /使用者名稱/.ssh/id_rsa.pub ‘-p 連接埠號碼 使用者名稱@106.75.52.44‘

ssh-copy-id -i /root/.ssh/id_rsa.pub ‘-p 22222 [email protected]‘

這裡可能需要等一段時間,反正我是等了挺久的時間,然後顯示要你輸入密碼:

[email protected]106.75.52.44‘s password:

輸入完密碼後,顯示:

Now try logging into the machine, with "ssh ‘-p 22222 [email protected]‘", and check in:
.ssh/authorized_keys

to make sure we haven‘t added extra keys that you weren‘t expecting.

表示成功了!

第三步: 遠程登入

[[email protected] ~]$ ssh [email protected]
Last login: Mon Oct 10 14:18:54 2016 from 192.168.161.135

ssh [email protected] -p 22222

 

遇到的大坑:

配置ssh免密碼登入後,仍提示輸入密碼

解決方案:
首先我們就要去查看系統的記錄檔
tail /var/log/secure -n 20

發現問題的所在:Authentication refused: bad ownership or modes for file

從字面上可以看出是目錄的屬主和許可權配置不當,尋找資料得知:SSH不希望home目錄和~/.ssh目錄對組有寫入權限,通過下面幾條命令改下

chmod g-w /home/zhangming
chmod 700 /home/zhangming/.ssh
chmod 600 /home/zhangming/.ssh/authorized_keys
然後我們再去登入,就能不用密碼進入了。

 

解決:centos配置ssh免密碼登入後仍要輸入密碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.