• 幕客老师召集小伙伴
  • 运维高手36项修炼
  • python自动化运维项目实战
  • nginx从入门到实战
  • 阿里云与Centos7实战

如何Git通过SSH的秘钥key建立信任

作为一个OP人员,管理git平凡的需要密码认证总是比较麻烦的,这是我们可以考虑用ssh key的方式来建立local server与git server的信任关系。

可以参考如下步骤:

步骤一、检查local server家目录上的key 是否存在?

span class="command">ls -al ~/.ssh

# Lists the files in your .ssh directory, if they exit

步骤二、如果不存在id_dsa.pub文件,则需要新建

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.

Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

Enter passphrase (empty for no passphrase): [Type a passphrase] 建议为空
# Enter same passphrase again: [Type passphrase again]

Your identification has been saved in /Users/you/.ssh/id_rsa.  表示新建立完成
# Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

步骤三、需要将你新建的 key加入到ssh -agent代理中
确保代理已经启动
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Agent pid 59566
将key加入到代理
ssh-add ~/.ssh/id_rsa

步骤四:需要登陆到gforge界面,将id_rsa.pub的公钥key内容,粘贴到个人用户界面的key设置中,并提交:

Add the copied key to GitHub:

  1.  

  2. Settings icon in the user bar

  3. In the top right corner of any page, click your profile photo, then clickSettings.

  4. SSH keys

  5. In the user settings sidebar, click SSH keys.

  6. SSH Key buttonClick Add SSH key.

  7. In the Title field, add a descriptive label for the new key. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air".
  8. The key field
  9. Paste your key into the "Key" field.
  10. The Add key button
  11. Click Add key.
  12. Confirm the action by entering your GitHub password.

步骤六,测试
可以通过ssh登陆看看是否可以不需要密码验证了,通过如下方式:
ssh -T git@github.com
# Attempts to ssh to GitHub
 
 
 

 

如何Git通过SSH的秘钥key建立信任

Pingbacks已打开。

引用地址

暂无评论

发表评论