Ubuntu服務器開啟密鑰登錄
1.使用SecureCRT創建私鑰和公鑰.
SecureCRT: Quick Connect -> Authentiation -> Public Key -> Properties -> Create Identity File -> DSA/RSA -> Set Passphrase -> Done
這個時候在指定目錄會生成兩個文件,例如,私鑰Identity和公鑰Identity.pub
2.創建一個新用戶
#useradd subsir -m #su subsir //切換到subsir用戶,以下的操作必須用subsir賬號操作,subsir必須有權限
3.在/home/roger目錄下創建.ssh文件夾并更改權限
# mkdir /home/subsir/.ssh # chmod 700 /home/subsir/.ssh
4.將公鑰 Identity.pub 傳到linux服務器,將SSH2兼容格式的公鑰轉換成為Openssh兼容格式
# ssh-keygen -i -f Identity.pub >> /home/subsir/.ssh/authorized_keys # chmod 600 /home/subsir/.ssh/authorized_keys
5.在SecureCRT里面設置登錄模式為PublicKey,并選擇剛剛創建的Identity文件作為私鑰
6.重啟Ubuntu服務器上SSH服務器
#sudo /etc/init.d/ssh restart
service sshd restart
7.由于已經設置了密鑰登錄,原來的密碼登錄就完全可以去掉
# vi /etc/ssh/sshd_config
#假如要修改端口:
#修改port 22 為 port 端口號
Protocol 2 /僅允許使用SSH2
PubkeyAuthentication yes /*啟用PublicKey認證
PasswordAuthentication no /*禁止密碼驗證登錄
重啟實例
用的阿里云服務器,如果直接連接,會報下面錯誤:
$ ssh root@47.94.132.115
Permission denied (publickey).
創建服務器的時候,連接秘鑰會生成并下載到本地(xishuai-key.pem),解決方式:
$ chmod 600 /users/xishuai/.ssh/xishuai-key.pem
$ ssh -i /users/xishuai/.ssh/xishuai-key.pem root@47.94.132.115

浙公網安備 33010602011771號