SSH通过CONFIG配置各种登陆

可能用习惯了XSHELL,CRT那种记录会话的登陆方式,命令行SSH好像缺少了登陆的快感,其实不然,只需要自行配置一个config文件即可

~ on  master! ⌚ 23:37:56
$ vim .ssh/config

Host $SSH_NAME
        HostName        $IPADDR
        Port            $PORT
        User            $USER
        IdentityFile    $PRIVATE_KEY

通过这种配置方式,下次只需要通过命令ssh $SSH_NAME就可以登陆目标主机了

比如我配置了两个

$ cat .ssh/config
Host devstack
        HostName        1.1.1.1
        Port            22
        User            root
        IdentityFile    /Users/lihui/server/dev.private

Host 37
        HostName        37.37.37.37
        Port            1111
        User            hzlihui15
        IdentityFile    /Users/lihui/server/back

Host jump-yun
        HostName        2.2.2.2
        Port            2222
        User            hzlihui15
        ForwardAgent    yes

Host jump-xiaoshan
        HostName        3.3.3.3
        Port            3333
        User            hzlihui15
        ForwardAgent    yes

那么登陆起来也很有快感

~ on  master! ⌚ 23:44:19
$ ssh devstack

 Last login: Wed Nov  4 23:31:32 2015 from 4.4.4.4
root@devstack:~#
root@devstack:~#
root@devstack:~#
root@devstack:~# logout
Connection to 1.1.1.1 closed.

~ on  master! ⌚ 23:44:30
$ ssh 37

Last login: Wed Nov  4 23:33:37 2015 from 4.4.4.4
hzlihui15@37-37-37-37:~$
hzlihui15@37-37-37-37:~$
hzlihui15@37-37-37-37:~$

 

这样只需要取一个面熟的名字,登陆起来也很舒服~!

发表评论