密碼登陸太麻煩了,使用密鑰簡單。更安全?也許。
生成密鑰,依提示來做。
ssh-keygen
在~/.ssh目錄得到兩個文件(密鑰對)
id_rsa id_rsa.pub
其中,.pub是公鑰,另外一個是私鑰。
公鑰放服務器上
ssh-copy-id -i id_rsa.pub user@foo.fffo.com
完成上面命令後,會在服務器的~/.ssh下發現文件authorized_keys,內含id_rsa.pub之內容
私鑰放本地,權限為600,否則登陸可能會出現類似下面的提示。
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for ‘/home/ewrwer/.ssh/id_rsa’ are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /home/ewrwer/.ssh/id_rsa
ewrwer@fewrwrw’s password:
本地配置~/.ssh/config內容類似下面
Host HostA
HostName HostA.domain.net
User useratA
IdentityFile ~/.ssh/id_rsa.HostAHost HostB
HostName HostB.domain.net
User useratB
IdentityFile ~/.ssh/id_rsa.HostB
然後就可以通過下面命令來登陸ssh了。
ssh HostA
參考資料:



![Lazy Lass [eXPLoReD] Lazy Lass [eXPLoReD]](http://static.flickr.com/7083/7272226034_3d95aba441_m.jpg)

最新评论