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
7.由於已經設置了密鑰登錄,原來的密碼登錄就完全可以去掉
# vi /etc/ssh/sshd_config
#假如要修改端口:
#修改port 22 為 port 端口號
Protocol 2 /僅允許使用SSH2
PubkeyAuthentication yes /*啟用PublicKey認證
PasswordAuthentication no /*禁止密碼驗證登錄