When I connect to my remote machine I do authenticate using a rsa key (I think is rsa, don't remember).

If I do ssh from a regular shell I get logged on the machine without a password. However if I do ssh from within tmux I get asked for a password.

What is different within tmux that I get asked a password and the ssh key is not used? How can I get to not type the password from within tmux?

2 Answers 2


Your tmux session was started before your ssh agent was started, so the SSH_AUTH_SOCK and SSH_AGENT_PID variables are not set inside it. There are two ways to solve this. You can either copy those variables into the tmux session or run ssh-agent inside tmux to get them set, then run ssh-add to add the key to your ssh agent.

  • Thanks a lot for the explanation. I have logged onto the remote machine using the ssh key, so that all relevant variables were set. Then started tmux (and even restored my session with tmux-resurrect) and now it indeed connects using the ssh key. Thanks a lot!
    – Rho Phi
    Dec 9, 2014 at 17:21
  • You may also find the man page useful, see openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/… and search for the section ENVIRONMENT where it talks about the set-environment and show-environment commands. Dec 10, 2014 at 2:59

You may want to look at the answers to a similar question on the Superuser SE site, Can I re-attach SSH key forwarding through a disconnected Screen session. The answers are likely the same.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .