Answer the question
In order to leave comments, you need to log in
Why doesn't ssh-agent find the key on a new terminal session?
Good afternoon, I
add the ssh key Documentation bitbucket , at this stage everything is smooth and ssh works, but when I log into the server again (logout of the current terminal session) I get an error
$git ls-remote
repository access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[email protected]:/home/b/frontend# eval 'ssh-agent'
SSH_AUTH_SOCK=/tmp/ssh-J4mjc2fCUI2r/agent.29034; export SSH_AUTH_SOCK;
SSH_AGENT_PID=29035; export SSH_AGENT_PID;
echo Agent pid 29035;
exec ssh-agent bash
Answer the question
In order to leave comments, you need to log in
Need to add bibucket host to ssh config
Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa
this happens because, on ssh-agent
startup, it gives the name of the socket, which is set to the environment variable SSH_AUTH_SOCK
( ssh-agent bash
makes this task easier by issuing it in a form suitable for execution in bash/shell). They are "lost" when re-login. So, in order to connect to a previously running ssh-agent
'u, you need to restore the path to its socket.
How to do it? For example, like this:
https://gist.github.com/martijnvermaat/8070533
Upd.
function __ssh_agent_find_sockets() {
local user=$(whoami)
find /tmp/ssh-* -user "$user" -name agent\* -printf '%[email protected] %p\n' 2>/dev/null | sort -k 1nr | sed 's/^[^ ]* //'
}
function __ssh_agent_restore() {
local found_socket=$(__ssh_agent_find_sockets | head -n 1)
export SSH_AUTH_SOCK="$found_socket"
}
function __ssh_agent_socket() {
# set up SSH agent socket symlink
export SSH_AUTH_SOCK_LINK="/tmp/ssh-$USER/agent"
if ! [ -r $(readlink -m $SSH_AUTH_SOCK_LINK) ] && [ -r $SSH_AUTH_SOCK ]
then
mkdir -p "$(dirname $SSH_AUTH_SOCK_LINK)" \
&& chmod go= "$(dirname $SSH_AUTH_SOCK_LINK)" \
&& ln -sfn $SSH_AUTH_SOCK $SSH_AUTH_SOCK_LINK
fi
}
function __ssh_agent_run_do() {
eval $(ssh-agent -s)
}
function __ssh_agent_run() {
test -z "$SSH_AUTH_SOCK" && __ssh_agent_run_do
__ssh_agent_socket
return
}
~/.bashrc
:source ~/.bash_functions
...
__ssh_agent_run
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question