当我使用 xubuntu 19.10 时,SSH 代理转发工作正常,但在将系统升级到 xubuntu 20.04 后,它不再工作。我从未更改过 /etc/ssh/config 或 /home/.ssh/config 。这是我当前的 ~/.ssh/config 的样子:
Host my_remote_server_ip
ForwardAgent yes
系统升级后,当我尝试在远程服务器中运行 git pull 时出现此错误:
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
答案1
似乎 ssh 代理没有自动启动。我将以下内容添加到我的.bashrc
(参见这里):
vi ~/.bashrc
# Start SSH Agent
#----------------------------
SSH_ENV="$HOME/.ssh/environment"
function run_ssh_env {
. "${SSH_ENV}" > /dev/null
}
function start_ssh_agent {
echo "Initializing new SSH agent..."
ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo "succeeded"
chmod 600 "${SSH_ENV}"
run_ssh_env;
ssh-add ~/.ssh/id_rsa;
}
if [ -f "${SSH_ENV}" ]; then
run_ssh_env;
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_ssh_agent;
}
else
start_ssh_agent;
fi
注销并以用户身份登录后,它的工作原理就像之前在 ubuntu 中一样。