Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'm working in various Linux environments through PuTTY connections which break from time to time. I'm looking for a solution to make the PuTTY windows persist (e.g. if I was editing a file, then after reconnecting I should be in the same editor with the same file open at the same place), with the following requirements:

  • it shouldn't require any manual setup at the beginning of the session or after reconnection (I don't want to type in screen or anything like that)
  • I have several windows open to the same machine with the same user, which tend to disconnect at the same time
  • the number/role of windows is not constant (it's not like I have an mc window, a mysql window and a "script runner" window; sometimes I use one window for search or for SVN commands, other times I need several at the same time)
  • sometimes I need to change the properties of the windows for a task (large window for grepping/editing, small windows because I need to see two of them at the same time, red background because I am modifying the live database in MySQL etc), so I need to get the same console back in the same window after a reconnect

Is there a way to achieve this? I suppose I should use screen or something equivalent, but how does it know which window I am reconnecting from? Is there some way to pass a unique window identifier to the shell from PuTTY?

share|improve this question
Screen or Tmux would indeed work, but I think that this would be working around symptoms. The real problem is that your network connections die somehow, taking your puTTYs with them. The real goal should be fixing that, not finding a way to work around restarting your ssh sessions (This will also affect other programs which will suffer from the same connection drops). – Hennes Dec 17 '12 at 10:31
You need a custom script running in the background, tracing your current actions (started commands) and logging them periodically updating the file - lets call it This file with contain all currently active jobs started by a specific user. After disconnection and re-connection, the profile.rc will start the script which will start all commands that it finds in "" file. The script can use screen command so you could have a split screen if you prefer. The script tracing the active commands could potentially distinguish running jobs based on the tty ID.. tbc – mnmnc Dec 17 '12 at 10:37
...and place the jobs in the separate files current.com1 current.com2 and so on. Then after reconnecting the script started by profile.rc would reconnect the first inactive group of commands to your reconnected session. If you connect the parallel session it would restart the second group of inactive jobs and so on... I do not think there is an existing tool for your demands but the script should not be that complicated to write. – mnmnc Dec 17 '12 at 10:40
@Hennes the timing out of inactive sessions is not a bug - its a feature and very important from the security point of view I might add. This is not something you should work-around. You can adjust the timeout settings on the server side in sshd.conf but you should never set it up to keep the session indefinitely. – mnmnc Dec 17 '12 at 10:42
I disagree. The time-out are not a replacement for security features. -- If I ssh into my server, take a coffee break (with locked desktop. On windows simple win-L), come back after the break and unlock my desktop then I do not expect my putty sessions die have died. – Hennes Dec 17 '12 at 11:49

The quick and clean solution

Edit your ~/.bashrc to run screen -r. Then you will be reattached to a running screen session automatically when you log in.

The fulfilling solution

  • Create a user for each screen session (Windows-window/PuTTY session) you intend to have open as a maximum.
  • Connect to the server using each of the newly created users and run "screen -S username" to start a session named with their username.
  • Append "screen -r $(whoami)" to each user's ~/.bashrc
  • Save a putty session for each of the users on your desktop or in PuTTY to add them to your superbar's jumplist or wherever you want your shortcuts, and use them to start up each session. This will also enable you to

EDIT: I would preferrably focus on fixing the timeout issue. It's a security feature, I know, but it shouldn't disconnect you while you are sending input.

share|improve this answer
This would only work if you have a single screen session on the server side, and it would only reconnect a single screen. The OP is saying he often uses multiple sessions. – mnmnc Dec 17 '12 at 10:48
This could be solved by using side-by-side windows within screen instead of multiple SSH sessions. – Time Sheep Dec 17 '12 at 10:49
Yeap - but only if you use single side by side session. If you use Text editor in one Putty session and on the other Putty session you use screen with split workspace - how would you reconnect to all of them? – mnmnc Dec 17 '12 at 10:52
That wasn't what I meant, I meant you could keep the text editor in a split workspace. Either way, this is more of a workaround than a solution. You could also use fixed screen session names. e.g. you create a user named steve, steve starts a screen session with "screen -S steve". You also create a user named greg, greg then starts his session with "screen -S greg". Edit each user's .bashrc to reattach to their respective session with "screen -r steve" and create a saved PuTTY session for each user. – Time Sheep Dec 17 '12 at 10:57
Yes. That is a nice solution - I agree. However I think I would not decide to do this as I would need to have potentially as many Users as combinations of screens with which I work. This means if i would like to change some settings for my profile globally, i would need to propagate those settings to all .profilerc files - am I right? – mnmnc Dec 17 '12 at 11:09

Look into mosh which is designed to reconnect terminal sessions after transient network failures. There are a bunch of caveats with mosh (different security considerations, potential loss of scrollback), but it definitely solves the re-connect-after-disconnect much smoother than putty.

share|improve this answer
Thanks. I heard about mosh, but as I understand it basically replaces SSH with its own protocol which is probably not mature enough for serious use. – Tgr Mar 3 '13 at 20:27

An old post I know, but just thought I'd mention the seconds between Keepalives setting on the Connection options tab - set this to a non-zero value to see if it helps - see for more info.

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.