Phenomenon: I have generated sshkey on the server and uploaded it to gitlab, but when I use SSH to pull the code on the server, I still need to enter the password.
The reasons are as follows:
I am using a mobile cloud server, which is not turned on by default ssh-agent
. If I want it to be turned on automatically every time I log in to the server, I need to ~/.bashrc
add the following configuration to the file:
if [ -z "$SSH_AUTH_SOCK" ] ; then
eval $(ssh-agent -s) # 每次登录服务器,都开启 ssh-agent
fi
ssh-add ~/.ssh/ssl_git_002 # 将我生成的 git 的私钥添加到 环境变量