Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 10. Command-Line Quickstart > Accessing the Command Line

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.

Note

Finding and running programs, such as Terminal, from a GUI is covered in Chapter 3, “Working with Unity,” as is logging it to a Linux system using a graphical interface. This chapter focuses on text-based logins and the use of Linux.


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:

Tip

This is tty1, one of six virtual consoles that Ubuntu provides. After you have accessed a virtual console, you can use the Ctrl+Alt + any of F1 through F6 to switch to a different console, tty1 through tty6. If you want to get back to the graphical interface, press Ctrl+Alt+F7. You can also switch between consoles by holding the Alt key and pressing either the left or the right cursor key to move down or up a console, such as tty1 to tty2.


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.

Note

Your password is not echoed back to you, which is a good idea. Why is it a good idea? Well, people are prevented from looking over your shoulder and seeing your screen input. It is not difficult to guess that a five-letter password might correspond to the user’s spouse’s first name.


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:

matthew@seymour:~$

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.

Tip

Navigating through the system at the command line can get confusing at times, especially when a directory name occurs in several places. Fortunately, Linux includes a simple command that tells you exactly where you are in the file system. It’s easy to remember because the command is just an abbreviation of present working directory, so type pwd at any point to get the full path of your location. For example, typing pwd after following these instructions shows /home/yourusername, meaning that you are currently in your home directory.

Using the pwd command can save you a lot of frustration when you have changed your directory half a dozen times and have lost track.


Logging Out

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.

Note

See Chapter 17, “Networking,” to see how to set up network interfaces with Linux to support remote network logins and Chapter 18 to see how to start remote access services (such as sshd).


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.
matthew@192.168.0.41'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:~$