Liunx 服务器添加 SSH 访问Git / CentOs
1、看看目录是否存在
ls -al ~/.ssh
2、生成密钥
ssh-keygen -t rsa -C "347969164@qq.com"
操作
Enter file in which to save the key (/home/qy/.ssh/id_rsa): #【按回车】
Enter passphrase (empty for no passphrase): #【输入密码】
密码 ****
Enter same passphrase again: # 【再次输入密码】
密码 ****
密钥文件目录
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:joUMKG8+3KkO8dbpRyvHYgOG8ufydZNL3jkMYYB6mO8 347969164@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| . |
| .. . |
|. .+. . |
| o+ .o .o |
|..oo o.S. |
|o*oo.o.+.. |
|oo*o=oo.*o |
| oo+E.=+ +o. |
| .o*+* o o. |
+----[SHA256]-----+
3、得到 agent pid
eval $(ssh-agent -s)
输出
Agent pid 22939
4、将 ssh 私钥添加到 ssh 代理中。如果使用不同的名称创建了密钥, 或者添加了具有不同名称的现有密钥, 请用私钥文件的名称替换该命令中的 id_rsa
ssh-add ~/.ssh/id_rsa
5、复制 SSH key 到剪切板
6、到Git 添加公钥
7、服务器确认
gitee 的
ssh -T git@gitee.com
github的
ssh -T git@github.com
操作流程
# The authenticity of host 'gitee.com (180.97.125.228)' can't be established.
# ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
# ECDSA key fingerprint is MD5:27:e5:d3:f7:2a:9e:eb:6c:93:cd:1f:c1:47:a3:54:b1.
# Are you sure you want to continue connecting (yes/no)? yes
# 输入 yes
# Warning: Permanently added 'gitee.com,180.97.125.228' (ECDSA) to the list of known hosts.
# Enter passphrase for key '/root/.ssh/id_rsa':
# 输入公钥密码
# Hi 简简单单OnlineZuozuo! You've successfully authenticated, but GITEE.COM does not provide shell access.
# 成功
转载:https://blog.csdn.net/qq_15071263/article/details/108771794
查看评论