touch ~/.ssh/config 配置config文件
下面对上述配置文件中使用到的配置字段信息进行简单解释:
Host
它涵盖了下面一个段的配置,我们可以通过他来替代将要连接的服务器地址。
这里可以使用任意字段或通配符。
当ssh的时候如果服务器地址能匹配上这里Host指定的值,则Host下面指定的HostName将被作为最终的服务器地址使用,并且将使用该Host字段下面配置的所有自定义配置来覆盖默认的/etc/ssh/ssh_config配置信息。
Port
自定义的端口。默认为22,可不配置
User
自定义的用户名,默认为git,可不配置
HostName
真正连接的服务器地址
PreferredAuthentications
指定优先使用哪种方式验证,支持密码和秘钥验证方式
IdentityFile
指定本次连接使用的密钥文件
实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #Default gitHub user Self Host github.com HostName github.com User git #默认就是git,可以不写 IdentityFile ~/.ssh/id_rsa.github
#Add gitLab user Host git@gitlab.com HostName gitlab.com User git IdentityFile ~/.ssh/id_rsa.gitlab
# gitee Host gitee.com Port 22 HostName gitee.com User git IdentityFile ~/.ssh/id_rsa.gitee
# 其他自己搭建的 Host git@git.startdt.net Port 22 HostName http://git.startdt.net User git IdentityFile ~/.ssh/lab_rsa.startdt
|