Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

1 Answer 1

You can use this pattern to solve your problem:

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.