- Feb 20, 2012
Accessing the Command Line
You can quickly access the terminal using the desktop menu option Terminal. This opens gnome-terminal, from which you can access the terminal while remaining in a GUI environment. This time, the terminal appears as white text on an aubergine (dark purple) background. This is the most common method for accessing the terminal for most desktop users.
The second most common way for graphical desktop users to access the command line is to press the key combination Ctrl+Alt+F1, after which Ubuntu switches to a black screen and a login prompt like this:
Ubuntu 11.10 oneric seymour ttyl seymour login:
Regardless of which way you access the terminal, using the virtual tty consoles accessible at Ctrl+Alt+F1-6 or via the windowed version atop your GUI desktop, you will find the rest of the usage details that we cover work the same. As you continue to learn and experiment beyond the contents of this book, you may start to discover some subtle differences between the two and develop a preference. For our purposes, either method works quite well.
There are many other ways to access and use the command line. You could use a traditional console with a monitor, keyboard, and mouse attached to the PC, but which boots into a command-line interface instead of a GUI. You can also connect to your system through a wired or wireless network using the telnet or ssh commands, as covered in Chapter 18, “Remote Access with SSH and Telnet.”
With that, let’s begin.
Text-Based Console Login
However you connect to a command-line interface, you start with a prompt similar to this one:
Ubuntu 11.10 oneric seymour ttyl seymour login:
Your prompt might vary, depending on the version of Ubuntu you are using and the method you are using to connect. In any event, at this prompt, type in your username and press Enter. When you are prompted for your password, type it in and press Enter.
At the login prompt, type your username and press the Enter key. You are asked for your password, which you type. Note that Ubuntu does not show any characters while you are typing in your password. This is a good thing because it prevents any shoulder surfers from seeing what you’ve typed or the length of the password.
Pressing the Enter key drops you to a shell prompt, signified by the dollar sign:
This particular prompt tells me that I am logged in as the user matthew on the system seymour and I am currently in my home directory; Linux uses the tilde (~) as shorthand for the home directory, which would usually be something like /home/matthew.
Use the exit or logout command or Ctrl+D to exit your session. You are then returned to the login prompt. If you use virtual consoles, remember to exit each console before leaving your PC. (Otherwise, someone could easily sit down and use your account.)
Logging In and Out from a Remote Computer
Although you can happily log in on your computer, an act known as a local login, you can also log in to your computer via a network connection from a remote computer. Linux-based operating systems provide a number of remote access commands you can use to log in to other computers on your local area network (LAN), wide area network (WAN), or the Internet. Note that you must have an account on the remote computer and the remote computer must be configured to support remote logins; otherwise, you won’t be able to log in.
The best and most secure way to log in to a remote Linux computer is to use ssh, the Secure Shell client. Your login and session are encrypted while you work on the remote computer. The ssh client features many command-line options, but can be simply used with the name or IP address of the remote computer, as follows:
matthew@seymour:~$ ssh 192.168.0.41 The authenticity of host '192.168.0.41 (192.168.0.41)' can't be established. RSA key fingerprint is e1:db:6c:da:3f:fc:56:1b:52:f9:94:e0:d1:1d:31:50. Are you sure you want to continue connecting (yes/no)? yes
The first time you connect with a remote computer using ssh, Linux displays the remote computer’s encrypted identity key and asks you to verify the connection. After you type yes and press Enter, you are warned that the remote computer’s identity (key) has been entered in a file named known_hosts under the .ssh directory in your home directory. You are also prompted to enter your password:
Warning: Permanently added '192.168.0.41' (RSA) to the list of known hosts. firstname.lastname@example.org's password: matthew@babbage~$
After entering your password, you can work on the remote computer, which you can confirm by noticing the changed prompt that now uses the name of the remote computer on which you are working. Again, because you are using ssh, everything you enter on the keyboard in communication with the remote computer is encrypted. When you log out, you return to the shell on your computer:
matthew@babbage~$ logout matthew@seymour:~$