ssh-config 管理

有时候,我们要管理很多台服务器,一个一个去连接,例如:

ssh username@ip -p port

这样非常痛苦的,因为IP地址不容易记忆。那怎么办?用ssh的config 来进行管理即可,具体如下:

vim ~/.ssh/config 

在当前用户的.ssh目录下创建一个 config 文件,格式如下:

Host name
    HostName  ip
    Port  port
  User  username
    IdentityFile path/to/id_rsa

例如:

➜  .ssh cat ~/.ssh/config
Host ssh1
    HostName 10.173.32.108
    Port 22
    User root
    IdentityFile /Users/wenjun/.ssh/ssh1

然后只需要执行

ssh ssh1

即可连接

➜ ssh ssh1
The authenticity of host '10.173.32.108 (10.173.32.108)' can't be established.
ECDSA key fingerprint is SHA256:KtMXK9uQgIAwzOkvvqncijKggykVjiRTuYnNH5gFslY.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.173.32.108' (ECDSA) to the list of known hosts.
[root@test ~]#
[root@test ~]#
[root@test ~]# exit
登出
Connection to 10.173.32.108 closed.