Running Linux, 5th Edition - Matthias Kalle Dalheimer [81]
Stopped (tty input)
You can solve this problem by bringing the job back into the foreground through the fg command. If you have many commands in the background, you can choose one of them by its job number or its process ID. For our long-lived gcc command, the following commands are equivalent:
$ fg %1
$ fg 21457
Don't forget the percent sign on the job number; that's what distinguishes job numbers from process IDs.
To get rid of a command in the background, issue a kill command:
$ kill %1
If you have started a program in the foreground, but want to put in the background later, most shells allow you to type Ctrl-Z. That key combination temporarily suspends the current foreground program. You can then type either fg as described before, to put it back in the foreground, or bg, to put it in the background.
Remote Logins and Command Execution
You are probably connected to a network, either within your own home or office, or through dial-up to the Internet. Sometimes you want to log in to another system, or copy a file to or from another system.
If you need help setting up networking, check Chapter 13 and the following chapters. In this section we assume you are on the network already. If you can view a web page in a browser, you're connected and can carry out the commands in this section. We'll use a package called SSH that's installed on most, if not all, Linux distributions.
SSH stands for Secure Shell, and denotes the project developers' focus on protecting your communications from snooping and hijacking. SSH has become an extremely respected and popular protocol for communicating between systems, and is supported on many different types of systems, such as the Putty graphical interface for Windows (http://www.chiark.greenend.org.uk/~sgtatham/putty).
Linux uses OpenSSH, a free software implementation (http://www.openssh.com). It rarely has bugs (although one will turn up once in a while, so for security reasons you should keep up with your distribution's updates), and it supports the latest standard, SSH protocol version 2. If you decide to do some heavy internetworking with SSH, you can get quite deep into it through SSH, The Secure Shell: The Definitive Guide (O'Reilly).
This section lays out the four or five commands you'll use most often. Suppose you have an account named mdw on a remote system called eggplant. You can log in as follows:
$ ssh -l mdw eggplant
The -l specifies the account on the remote system. Another syntax with identical effects is:
$ ssh mdw@eggplant
If your account name is the same on the local and remote systems, you can omit the name and just enter:
$ ssh eggplant
Each time you start an ssh session, it prompts for the password of the account on the remote system.
During the session, if you have to do something on your local machine, you don't have to log out or switch windows. Suspend the remote login session by entering a tilde character (~) followed by Ctrl-Z. (Sometimes the tilde is not caught by SSH; if it isn't, try again. You're successful if the tilde is not displayed.) To pick up the session you suspended, use fg as for local programs you suspend.
You might want to run a single command instead of starting up a shell on the remote system; if so, just enter the command after the hostname:
$ ssh -l mdw eggplant rm logfiles/temp_junk
Or, if you can omit your name:
$ ssh eggplant rm logfiles/temp_junk
Filenames such as logfiles/temp_junk are interpreted as if you were located in your home directory (the directory you'd be in if you logged in). Use absolute pathnames (such as /home/mdw/logfiles/temp_junk) if you want to make sure you're naming the right file in the right location.
The manpage for ssh can fill in interesting details, such as how to run X Window System graphical programs over SSH, and how to eliminate the annoyance of having to enter your password at each invocation of the command. (To be really robust, though, you may have to play around with configuration files beyond what the manpage tells you.)
You can copy files using