Reptyr ашиглан SSH session буцаан ашиглах

Дусал нэвтэрхий толь-с
17:08, 9 Аравдугаар сар 2022-ий байдлаарх Almas (Яриа | оруулсан хувь нэмэр) хэрэглэгчийн хийсэн залруулга
(ялгаа) ←Хуучны засвар | Одоогийн засвар (ялгаа) | Дараагийн засвар→ (ялгаа)


Use reptyr to reparent a running program to a new terminal. HOW TO:

Lets assume that we have connected to ssh from some previous IP address aaa.bbb.ccc.old, then run aptitude process, and in the middle of the work that connection got broken.

We login with ssh again (optionally from a different IP address aaa.bbb.ccc.new). The current connection uses pty/1 pseudo-terminal:

$ tty /dev/pts/1

But there are 2 open connections, the current pts/1 one, and the old broken one using pts/0:

$ who user pts/0 2022-02-22 22:00 (aaa.bbb.ccc.old) user pts/1 2022-02-22 22:11 (aaa.bbb.ccc.new)

Lets list all shells and their subprocesses:

$ ps auf USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND user 2000 1.3 0.5 10168 5236 pts/1 Ss 22:11 0:00 -bash user 2001 0.0 0.3 10620 3304 pts/1 R+ 22:11 0:00 \_ ps auf user 1000 0.0 0.5 10168 5132 pts/0 Ss 22:00 0:00 -bash user 1001 5.8 16.0 46639 15839 pts/0 Sl+ 22:00 0:03 \_ aptitude root 820 0.0 0.1 5836 1840 tty1 Ss+ 22:00 0:00 /sbin/agetty -o -p -- \u --noclear tty1 linux root 810 0.0 0.2 7360 2260 ttyS0 Ss+ 22:00 0:00 /sbin/agetty -o -p -- \u --keep-baud 115200,38400,9600 ttyS0 vt220

There are 2 bash shells: the current pts/1 one with PID 2000 running ps auf and the old broken pts/0 one with PID 1000 running aptitude

Lets reconnect to the old one with reptyr:

$ sudo reptyr -T 1000

This way we gain access to the old shell and its subprocesses. Since aptitude uses ncurses, you may need to press Ctrl+L or resize the terminal emulator's window to force it to repaint itself. Now we can quit aptitude, and then exit the old shell (1000), thus returning to our new shell (2000) with only 1 connection remaining, which is the current one:

$ who user pts/1 2022-02-22 22:11 (aaa.bbb.ccc.new)


Source: https://serverfault.com/questions/19634/how-to-reconnect-to-a-disconnected-ssh-session