~/.ssh/config
cho cả GitHub và GitLab:
# Cấu hình cho GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_key
TCPKeepAlive yes
IdentitiesOnly yes
# Cấu hình cho GitLab
Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/gitlab_key
TCPKeepAlive yes
IdentitiesOnly yes
github.com
và gitlab.com
)Host
git
khi sử dụng giao thức SSH với GitHub hoặc GitLabChạy lệnh sau để kiểm tra kết nối SSH:
ssh -T git@github.com
ssh -T git@gitlab.com
Nếu nhận được thông báo như sau thì đã thành công:
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
Welcome to GitLab, @your-username!
Nếu bạn sử dụng git remote theo kiểu:
git@github.com:username/repo.git
git@gitlab.com:username/repo.git
Thì cấu hình trên là đủ. Nếu bạn sử dụng host alias (ví dụ git@github-alias:...
), bạn cần thay Host
thành alias đó.
Nếu cần mình kiểm tra file ~/.ssh/config
cụ thể của bạn, hãy gửi nội dung để mình hỗ trợ thêm.