Выбрать главу

Access Variable Data Files in the /var Directory

The /var directory contains subdirectories used by various system services for spooling and logging. Many of these variable data files, such as print spooler queues, are temporary, whereas others, such as system and kernel logs, are renamed and rotated in use. Incoming electronic mail is usually directed to files under /var/spool/mail.

Linux also uses /var for other important system services. These include the topmost File Transfer Protocol (FTP) directory under /var/ftp (see Chapter 20, "Remote File Serving with FTP"), and the Apache web server's initial home page directory for the system, /var/www/html. (See Chapter 17, "Apache Web Server Management," for more information on using Apache.)

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 dialup 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.

NOTE

This chapter focuses on text-based logins and use of Linux. Graphical logins and using a graphical desktop are described in Chapter 3.

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:

Fedora release 8 (Werewolf)

Kernel 2.6.23-1.217 fc8 on an i686

login:

Your prompt might vary, depending on the version of Fedora 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.

NOTE

Note that 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 how many characters are on your screen. It is not difficult to guess that a five-letter pass word might correspond to the user's spouse's first name!

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.

NOTE

See Chapter 14, "Networking," to see how to set up network interfaces with Linux to support remote network logins and Chapter 11 to see how to start remote access services (such as sshd).

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@teletran ~]$ ssh 192.168.0.10

The authenticity of host '192.168.0.10 (192.168.0.10)' can't be established.

RSA key fingerprint is 32:90:31:1e:31:1c:a8:d4:9a:0b:07:78:93:9d:65:df.

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.10' (RSA) \

to the list of known hosts.

andrew@192.168.0.41's password:

andrew@fedora:~$

After entering your password, you can then work on the remote computer. Again, every thing 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

► LD_LIBRARY_PATH — To declare the location of important software libraries (because most, but not all, Linux commands use shared resources)