我们再登录SSH时,经常需要输入 用户名@服务器 地址,很不方便,于是乎,就有小伙伴就想别这么麻烦简单一点方法如下:
添加SSH配置文件: [/etc/ssh/ssh_config] 或者 [~/.ssh/config]
[/etc/ssh/ssh_config] | [~/.ssh/config]
#HOST 别名 #hostname 服务器 #user 用户名 #IdentifyFile 本机公钥地址 # 可选 #IdentitiesOnly yes #可选 #------------------------- Host server1 hostname d111.sina.com user sina IdentifyFile ~/.ssh/ssh_pub.pub IdentitiesOnly yes
文件创建好之后,就可以直接使用登录了
ssh server1
注释项大概如下:
- HostName 指定登录的主机名或IP地址
- Port 指定登录的端口号
- User 登录用户名
- IdentityFile 登录的公钥文件
- IdentitiesOnly 只接受SSH key 登录
- PubkeyAuthentication