Accessing the Command Line
You can quickly access the terminal by 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 18.04 seymour ttyl seymour login:
Regardless of which way you access the terminal—using the virtual tty consoles accessible at Ctrl+Alt+F1 through F6 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 might start to discover some subtle differences between the two methods 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 that 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 19, “Remote Access with SSH, Telnet, and VNC.”
Text-Based Console Login
No matter which way you connect to a command-line interface, you start with a prompt similar to this one:
Ubuntu 18.04 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.
Pressing the Enter key drops you to a shell prompt, signified by the dollar sign:
This particular prompt says that the user is logged in as the user matthew on the system seymour and is currently in the 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 press 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
You can happily log in on your computer, an act known as a local login. In addition, you can 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 then 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. email@example.com'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:~$