Skip to main content

Gitlab配置SSH访问

note

适用的操作环境
*nix / mac

  1. 生成公钥
ssh-keygen -t rsa -f ~/.ssh/id_rsa.self -C "邮箱"
  1. 在GitLab中注册公钥 Settings->SSH keys中,增加公钥(id_rsa.self.pub)内容

  2. 生成并编辑~/.ssh/config

cd ~/.ssh
touch config
vim config

config文件中,输入:

host [别名]
hostname [gitlab访问地址(域名/ip:端口)]
user [gitlab的登录名]
IdentityFile ~/.ssh/id_rsa.self
  1. 验证
ssh -T git@47.115.47.218

输出结果:

Welcome to GitLab, @leon!