1.SSH密钥生成
1 | --设置别名 例如self_jamison |
运行命令后不要一路回车,分别在第一次对话出现 “Enter file in which to save the key” 的时候输入文件名,第二次会话是让你输密码,一般回车密码设置为空就好了。第三次再次确认密码,同样回车。
2.配置config 在~/.ssh下
创建config文件
1
touch config
添加如下内容
1
2
3
4
5
6
7
8
9
10
11
12Host github.com
Hostname ssh.github.com
User JamisonDong
AddKeysToAgent yes
IgnoreUnknown UseKeychain
IdentityFile ~/.ssh/github_jamison(self)
Host git.sankuai.com
User dongjiancheng
AddKeysToAgent yes
IgnoreUnknown UseKeychain
IdentityFile ~/.ssh/id_ed25519(work)
[!字段解释]
Host myhost(这里是自定义的host简称,以后连接远程服务器就可以用命令ssh myhost)
HostName 主机名可用ip也可以是域名(如:github.com或者bitbucket.org)
Port 服务器open-ssh端口(默认:22,默认时一般不写此行)
PreferredAuthentications 配置登录时用什么权限认证–可设为publickey,password publickey,keyboard-interactive等
IdentityFile 证书文件路径(如~/.ssh/id_rsa_)
User 登录用户名(如:git)*
3.测试连接
1 | ssh -T git@github.com |
运行命令后如果出现“Hi xxxx! You’ve successfully authenticated, but GitHub does not provide shell access.”,其中“xxxx”为你配置的 User 名字,这时恭喜你,配置成功了~