说明:
- git服务器:git.xxx.com
- 认证方式:ssh
- ssh key:.ssh/id_rsa
笔者个人理解的 ssh {user}@{server} 过程:
// Host git.xxx.com
// User {other}
// IdentityFile ~/.ssh/id_rsa
// this is client logic
config = find_config(server)
// config: {"User": other, "IdentityStr": read("IdentityFile")} .etc
if config is not null:
body = {"to": user}.extend(config)
request(server, body)
body = receive(request)
user, other, IdentityStr = body["to"], config["User"], config["IdentityStr"]
// this is server logic
auth_keys = read("/home/$other/.ssh/authorized_keys")
if IdentityStr is not null && IdentityStr in auth_keys:
auth(IdentityStr, random())
else:
response(server_public_key, "please input password")
以下现象理解
未配置.ssh/config
-
ssh {user}@git.xxx.com
{user}@git.xxx.com’s password:
Client未找到git.xxx.com的配置信息,即发送空请求,Server将采取口令认证
-
[email protected]’s password:
Client未找到git.xxx.com的配置信息,即发送空请求,Server将采取口令认证
已配置config
-
ssh {user}@git.xxx.com
{user}@git.xxx.com’s password:
Client找到git.xxx.com的配置信息,并发送包含认证信息的请求
但是Server端没有在/home/{user}/.ssh/authorized_keys中找到匹配的项,于是采取口令认证 -
PTY allocation request failed on channel 0
Welcome to GitLab, @{user}!
Connection to git.xxx.com closed.Client找到git.xxx.com的配置信息,并发送包含认证信息的请求
并且Server端在/home/git/.ssh/authorized_keys中找到匹配的项,于是公私钥认证,最后认证通过
ssh 命令
ssh [-i identity_file] [-l login_name] [user@]host[:port]
注意点
当ssh出现异常时,通常注意检查一下几点
- local: config(登入配置):登入至哪个用户,以什么身份登入,登入时使用的认证私钥
- server: authorized_keys(是否 允许 认证)
- local: know_hosts(服务器IP调整时)
gitlab使用时的配置
gitlab开始使用时 – 注意协议:SSH | HTTPS
gitlab 之 SSH
- ssh-keygen -t rsa -C “comment” -f filename
- 添加 xxx.pub 至 服务端(gitlab)上
- 配置 .ssh/config 添加 对应host的配置
- 使用
gitlab 之 HTTPS
- git config --global http.sslVerify “false”
- 正常使用