Feng’ Blog

Git SSH 配置
桌面 git base here$ git config --global user.name "名字&...
扫描右侧二维码阅读全文
21
2019/01

Git SSH 配置

桌面 git base here

$ git config --global user.name "名字"

$ git config --global user.email "邮箱"

QQ20190121-204709.png

一、生成密钥对

查看当前系统是否有密钥

cd ~/.ssh ls authorized_keys2 id_dsa known_hosts config id_dsa.pub

如果没有就创建

$ ssh-keygen -t rsa -C "your_email@youremail.com"按enter即可

Your public key has been saved in /home/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@youremail.com(当最后显示这个的时候,就说明你的密钥创建成功了)

查看你生成的密钥

$ cat ~/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0X6L1zLL4VHuvGb8aJH3ippTozmReSUzgntvk434aJ/v7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8vR3c8E7CjZN733f5AL8uEYJA+YZevY5UCvEg+umT7PHghKYaJwaCxV7sjYP7Z6V79OMCEAGDNXC26IBMdMgOluQjp6o6j2KAdtRBdCDS/QIU5THQDxJ9lBXjk1fiq9tITo/aXBvjZeD+gH/Apkh/0GbO8VQLiYYmNfqqAHHeXdltORn8N7C9lOa/UW3KM7QdXo6J0GFlBVQeTE/IGqhMS5PMln3 admin@admin-PC

  • 登录gitlab、github、码云等托管账户,选择ssh设置,添加你的秘钥就可以了
  • 完成以后,验证下这个key是不是正常工作:

$ ssh -T git@github.com Attempts to ssh to github

修改git的remote url

使用命令 git remote -v 查看你当前的 remote url

$ git remote -v origin https://github.com/someaccount/someproject.git (fetch) origin https://github.com/someaccount/someproject.git (push)

如果是以上的结果那么说明此项目是使用https协议进行访问的(如果地址是git开头则表示是git协议)

修改你的上传地址

git remote set-url origin git@github.com:someaccount/someproject.git

然后你可以再用命令 git remote -v 查看一下,url是否已经变成了ssh地址。

然后你就可以愉快的使用git fetch, git pull , git push,再也不用输入烦人的密码了

Last modification:January 21st, 2019 at 08:48 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment