2

For some network reasons, my previous SSH sessions to server have disconnected. When I create a new session, I find the previous session still exist:

[root@localhost ~]# who
root     pts/0        2015-03-25 21:35 (10.1.1.1)
root     pts/1        2015-03-25 21:36 (10.1.1.1)
root     pts/2        2015-03-26 01:44 (10.1.1.1)

The pts/0 and pts/1 are previous session terminals. And there are still some progresses running on them, such as vim:

root      2953  2906  0 Mar25 pts/0    00:00:01 vim getpasswd.sh

I want to re-login pts/0 to continue running vim progress, Is it possible? How can I do it?

0
4

You are already re-logged in with the new ssh session that you set up. If you want to connect the old edit session to you newly logged in session you can try reptyr which "reparents a running program to a new terminal".

If this disconnecting happens often there are multiple things you can do:

  • set ServerAliveInterval and/or TCPKeepAlive in /etc/ssh/ssh_config (or with -o from the commandline) on the client side (as commented by @Lambert)
  • set ClientAliveInterval and/or TCPKeepAlive in /etc/ssh/sshd_config on the server
  • look at tmux, or screen, which make it easy to reconnect to a session;
  • install mosh, on the client and the server, which sets up a session using ssh that then survives reconnects as long as the server nor the client dies (i.e. when the session connection was interrupted, IP address of one of the two machine changes, etc.).
2
  • 1
    You also might have a look at the SSH ServerAliveInterval setting to prevent network components from dropping sessions after a specified idle time. – Lambert Mar 26 '15 at 7:10
  • @Lambert Yes, updated the answer with that info. – Anthon Mar 26 '15 at 10:55

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