23.13. Stopping Remote Login Sessions
Once you start telnet, rlogin, rsh, and ssh for an interactive login, they basically "take over" your shell. Your keystrokes are sent to the shell running on the remote system. So if you type CTRL-z, it won't stop the telnet (or whatever) job: it'll stop the job running on the remote system.
It can be very handy to suspend a connection to a remote system and resume it, sometime later, with fg. Most of the remote login utilities let you do that.
To stop a telnet session, start by pressing the escape character. By default, this is CTRL-] (Control-right bracket). You should get a telnet command prompt. Type z to suspend the job, Here's how that looks:
myhost$ telnet remhost Trying 22.214.171.124... Connected to remhost. Escape character is '^]'. SunOS 5.6 login: whoever ... remhost% CTRL] telnet> z + Stopped telnet remhost myhost$
You can use other commands at the telnet command prompt. For a list, see your manual page or type help at the prompt. If you get to that prompt accidentally and don't want to stop the telnet session, simply press ENTER once.
Other remote-login utilities don't have a command prompt. Their control commands start with ENTER-tilde (~) and one more control character. The command to stop the session is ENTER, then tilde, then CTRL-z. It won't appear on your screen as you type it (if it does appear, it didn't work . . . try again). For example:
myhost$ ssh remhost Last login: Fri Dec 22 09:08:31 2000 from myhost NetBSD 1.4.2A (GENERIC) #6: Wed May 31 06:12:46 EST 2000 remhost% remhost% ~CTRL-z + Stopped ssh remhost myhost$
Notice the extra prompt: it shows me pressing ENTER first, before typing the tilde. That isn't necessary if you pressed ENTER to complete the previous command line -- but I tend to do it all the time, "just in case" I didn't type that ENTER.
You can stop the remote session in the middle of an interactive job, like using a text editor. But I'd recommend getting to a shell prompt on the remote system first, if you can. (For example, stop the remote job with CTRL-z so you'll get a shell prompt on the remote system.) Otherwise, if you bring the remote session into the foreground while you're in the middle of a full-screen editing job there, for example, the remote system won't know that it's supposed to redraw the screen when you come back online. Worse, if you forget where you were on the remote system, you might type a key that could do something disastrous, like deleting lines of the file you're editing. Stopping and starting from a known point -- a shell prompt -- is the best way I've found.
Copyright © 2003 O'Reilly & Associates. All rights reserved.