ssh-keygen + ssh-copy-id 無密碼登錄遠程服務器

1.在~/.ssh/ 下生成密鑰

xx@xx:~/.ssh$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_xx -C "Key for ssh  stuff"

這裏寫圖片描述

  1. 使用剛生成的密鑰, 用ssh-copy-id 將服務器地址加入控制,如果需要制定端口號,在地址後面要指定端口號纔可以,你可以基於一個密鑰加入多個遠程地址,只需要改變[email protected]即可
xx@xx:~/.ssh$ ssh-copy-id -i id_rsa_xx.pub user_name@xxx.xx.xxx.xx
xx@xx:~/.ssh$ ssh-copy-id -i id_rsa_xx.pub user_name@xxx.xx.xxx.xx -p xx

這裏寫圖片描述

3.爲了不輸入一長串的ssh 命令 在~/.ssh下創建一個config

xx@xx:~/.ssh$ touch config
xx@xx:~/.ssh$ chmod 700 config (修改權限)
xx@xx:~/.ssh$ vi config (編輯文件)

這裏寫圖片描述

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