服務器配置
服務器配置免密登錄,請參考以下鏈接文章
http://blog.csdn.net/kwinh/article/details/54134859
客服端配置
生成密鑰
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/TOYOTA/.ssh/id_rsa): id_rsa_1024
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_1024.
Your public key has been saved in id_rsa_1024.pub.
The key fingerprint is:
SHA256:mlWG1odeg3evLHgP4vPnjjYJCCBONY/DATi2ZelrxPI TOYOTA@DESKTOP-O7FUOAH
The key's randomart image is:
+---[RSA 2048]----+
| ..o= |
|o.o=.= o o |
|.+*.+.. o * = . |
| o.+ ... + + o . |
| + . .S.. .|
| E +. .. . . |
| . o o.+.o |
| ..o+=. |
| .+o=+ |
+----[SHA256]-----+
配置服務器
拷貝公鑰到遠程服務器上,或則其他地方
scp ~/.ssh/id_rsa_1024.pub username@hostname.com:~/.ssh/
然後登錄服務器後,將剛生成的公鑰追加到~/.ssh/authorized_keys
文件中
ssh username@hostname.com
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
編輯客服端ssh配置文件
編輯~/.ssh/config
文件,如果文件不存在則新建
#One
Host aliasName1
HostName 192.168.1.161
User root
IdentityFile ~/.ssh/id_rsa_1024
#Two
Host aliasName2
HostName 192.168.1.162
User root
Port 2233
#後面跟着的是註釋
Host 別名
HostName 服務器地址也可以是域名(如:www.xxx.com)
User 用戶名
Port 端口號 可省略 默認爲22
IdentityFile 私鑰地址 可省略 默認爲~/.ssh/id_rsa