Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

  • Print
  • + Share This
This chapter is from the book

Logging In to and Working with Linux

You can access and use a Linux system in a number of ways. One way is at the console with a monitor, keyboard, and mouse attached to the PC. Another way is via a serial console, either by dial-up via a modem or a PC running a terminal emulator and connected to the Linux PC via a null modem cable. You can also connect to your system through a wired or wireless network, using the telnet or ssh commands. The information in this section shows you how to access and use the Linux system, using physical and remote text-based logins.

Text-based Console Login

If you sit down at your PC and log in to a Linux system that has not been booted to a graphical login, you see a prompt similar to this one:

Ubuntu 9.10 karmic karmic-dev ttyl
karmic-dev login:

Your prompt might vary, depending on the version of Ubuntu you are using. 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.

Logging Out

Use the exit or logout commands to exit your session. Type the command and press Enter. 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 not only must you have an account on the remote computer, but 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 (barring future exploits) to log in to a remote Linux computer is to use the ssh or Secure Shell client. Your login and session are encrypted while you work on the remote computer. The ssh client features many different command-line options, but can be simply used with the name or IP address of the remote computer, like this:

[andrew@karmic-dev ~]$ ssh
The authenticity of host ' (' 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)?


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 '' (RSA) to the list of known hosts.
andrew@'s password:

After entering your password, you can then work on the remote computer. Again, everything you enter on the keyboard in communication with the remote computer is encrypted. Use the exit or logout commands to exit your session and return to the shell on your computer.

Using Environment Variables

A number of in-memory variables are assigned and loaded by default when the user logs in. These variables are known as shell environment variables, which can be used by various commands to get information about your environment, such as the type of system you are running, your home directory, and the shell in use. Environment variables are used by Linux operating systems to help tailor the computing environment of your system, and include helpful specifications and setup, such as default locations of executable files and software libraries. If you begin writing shell scripts, you might use environment variables in your scripts. Until then, you only need to be aware of what environment variables are and do.

The following list includes a number of environment variables, along with descriptions of how the shell uses them:

  • PWD To provide the name of the current working directory, used by the pwd command (such as /home/andrew/foo)
  • USER To declare the user's name, such as andrew
  • LANG To set language defaults, such as English
  • SHELL To declare the name and location of the current shell, such as /bin/bash
  • PATH To set the default location of executable files, such as /bin, /usr/bin, and so on
  • TERM To set the type of terminal in use, such as vt100, which can be important when using screen-oriented programs, such as text editors
  • MACHINE To declare system type, system architecture, and so on

At the command line, you can use the env or printenv commands to display these environment variables, like so:

   $ env



















LESSOPEN=| /usr/bin/lesspipe %s



LESSCLOSE=/usr/bin/lesspipe %s %s





This abbreviated list shows a few common variables. These variables are set by configuration or resource files contained in the /etc, /etc/skel, or user /home directory. You can find default settings for bash, for example, in /etc/profile, /etc/bashrc, .bashrc, or .bash_profile files installed in your home directory. Read the man page for bash for details about using these configuration files.

One of the most important environment variables is $PATH, which defines the location of executable files. For example, if, as a regular user, you try to use a command that is not located in your $PATH (such as the imaginary command command), you will see something like this:

$ command
-bash: command: command not found

However, you might know that command is definitely installed on your system, and you can verify this by using the whereis command, like so:

$ whereis command
command: /sbin/command

You can also run the command by typing its full pathname, or complete directory specification like this:

$ /sbin/command

As you can see in this example, the command command is indeed installed. What happened is that by default, the /sbin directory is not in your $PATH. One of the reasons for this is that commands under the /sbin directory are normally intended to be run only by root. You can add /sbin to your $PATH by editing the file .bash_profile in your home directory (if you use the bash shell by default, like most Linux users). Look for the following line:


You can then edit this file, perhaps using the vi editor (discussed in this chapter), to add the /sbin directory like so:


Save the file. The next time you log in, the /sbin directory is in your $PATH. One way to use this change right away is to read in the new settings in .bash_profile by using the bash shell's source command like so:

$ source .bash_profile

You can now run commands located in the /sbin directory without the need to explicitly type the full pathname.

Some Linux commands also use environment variables, for example, to acquire configuration information (such as a communications program looking for a variable such as BAUD_RATE, which might denote a default modem speed).

To experiment with the environment variables, you can modify the PS1 variable to manipulate the appearance of your shell prompt. If you are working with bash, you can use its built-in export command to change the shell prompt. For example, if your default shell prompt looks like

[andrew@laptop ~]$

You can change its appearance by using the PS1 variable like this:

$ PS1='$OSTYPE r00lz ->'

After you press Enter, you see

linux-gnu r00lz ->
  • + Share This
  • 🔖 Save To Your Account