Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've added the following lines (taken from here) to my .bashrc to automatically start a tmux session on login:

if [ "$PS1" != "" -a "${STARTED_TMUX:-x}" = x -a "${SSH_TTY:-x}" != x ]
        sleep 1
        ( (tmux has-session -t remote && tmux attach-session -t remote) || (tmux new-session -s remote) ) && exit 0
        echo "tmux failed to start"

However, this seems to breaks ssh agent forwarding on subsequent logins. Is there a way around this?

share|improve this question

You can use this pattern to solve your problem: http://superuser.com/questions/180148/how-do-you-get-screen-to-automatically-connect-to-the-current-ssh-agent-when-re

That allows you to have the SSH agent connection dynamically updated to reflect each connection; I think it uses screen, but tmux should be very much the same pattern.

The principal is to use a symlink to the SSH agent socket, which can change, inside tmux - and then update that symlink when you connect in a new SSH session.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.