创建和配置ssh keys for gitlab

一、为gitlab.com建立ssh key

  • 建立本机的ssh publish key

git config --global user.name "you name"

git config --global user.email "aa@bb.com"

  • 生成ssh private key

1.查看是否存在ssh private key: cd ~/.ssh,如果没有密钥则不会有文件夹,有就做好备份删除;

2.生成密钥

ssh-keygen -t rsa -C "aa@bb.com"

 按3个回车,密码为空;

最后得到了两个文件:id_rsa和id_rsa.pub

二、配置ssh客户端

  • 在gitlab.com上添加ssh密钥

这里是添加id_rsa.pud里的公钥,打开gitlab.com,登录自已的账号,然后添加。

  • 配置config

进入ssh目录:cd ~/.ssh/

执行命令:sudo gedit config,打开文本后输入以下内容,注意Hostname的值是输入自已的,

 

复制代码
User git
Hostname gitlab.yourwebsite.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive yes
IdentitiesOnly yes
//如果你要走本地代理
ProxyCommand nc -x 127.0.0.1:1080 %h %p
复制代码

 

保存与退出;

 

  • 测试是否成功

ssh git@yourwebsite.com

如果成功会显示:

 

PTY allocation request failed on channel 0
Welcome to GitLab, @youname!
Connection to xx.com  closed.

 

如果出现:the authenticity of host gitlab.com can't be established..

请执行:

eval $(ssh-agent -s)

然后:

ssh-add ~/.ssh/id_rsa

 参考此文章

 

如果要配置多个id_rsa,请参考这里;如添加了bitbucket.org的代码访问后,还要修改~/.ssh下的config文件,添加对应的Hostname和IdentityFile

 

 

posted @   johnny_zhao  阅读(499)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示