Tuesday, January 6, 2009

Becoming Super User

Though the normal way to become the super user is to log in as root, sometimes that is not convenient. For example, you may be logged into a regular user account and just want to make a quick administrative change to your system without having to log out and log back in. Or, you may need to log in over the network to make a change to a Linux system but find that the system doesn’t allow root users in from over the network.
The answer is that you can use the su command. From any Terminal window or shell, you can simply type:
$ su
Password: ******
#

When you are prompted, type in the root user’s password. The prompt for the regular user ($) will be changed to the super user prompt (#). At this point, you have full permission to run any command and use any file on the system. However, one thing that the su command doesn’t do when used this way is read in the root user’s environment. As a result, you may type a command that you know is available and get the message "command not found." To fix this problem, you can use the su command with the dash (−) option instead, as follows:
$ su −
Password: ******
#

You still need to type the password, but after you do that, everything that normally happens at login for the root user will happen after the su command is completed. Your current directory will be root’s home directory (probably /root), and things like the root user’s PATH variable will be used. With the other way of running root, you would not have changed directories or the environment of the current login session.

Using the root Login

The root user has complete control of the operation of your Red Hat Linux system. That user can open any file or run any program. The root user also installs applications and adds accounts for other people who use the system.
When you first install Red Hat Linux, you should have added a password for the root user. You need to remember and protect this password. You will need it to log in as root or to obtain root permission while you are logged in as some other user. The home directory for the root user is /root. That and other information associated with the root user account is located in the /etc/passwd file. Here is what the root entry looks like in the /etc/passwd file:
root:x:0:0:root:/root:/bin/bash
This shows that for the user named root, the user ID is set to 0 (root user), the group ID is set to 0 (root group), the home directory is /root, and the shell for that user is /bin/bash. You can change the home directory or the shell used, if you like, by simply editing the values in this file.
Aliases for the rm, cp, and mv commands allow those commands to be run with the −i option. This prevents massive numbers of files being removed, copied, or moved by mistake. The −i option causes each deletion, copy, or move to prompt you before the actual change is made.

Sunday, January 4, 2009

Understanding System Administration

Red Hat Linux, like other UNIX systems, was intended for use by more than one person at a time. Multiuser features allow many people to have accounts in Red Hat Linux, with their data kept secure from others. Multitasking allows many people to use the computer at the same time. Sophisticated networking protocols and applications make it possible for a Red Hat Linux computer to extend its capabilities to network users and computers around the world. The person assigned to manage all of this stuff is referred to as the system administrator.
Even if you are the only person using a Red Hat Linux system, system administration is still set up to be separate from other computer use. To do most tasks, you need to be logged in as the root user (also referred to as the super user). Other users cannot change, or in some cases, even see some of the configuration information for a Red Hat Linux system. In particular, security features such as passwords are protected from general view.

Using the root Login
The root user has complete control of the operation of your Red Hat Linux system. That user can open any file or run any program. The root user also installs applications and adds accounts for other people who use the system.
When you first install Red Hat Linux, you should have added a password for the root user. You need to remember and protect this password. You will need it to log in as root or to obtain root permission while you are logged in as some other user. The home directory for the root user is /root. That and other information associated with the root user account is located in the /etc/passwd file. Here is what the root entry looks like in the /etc/passwd file:
root:x:0:0:root:/root:/bin/bash
This shows that for the user named root, the user ID is set to 0 (root user), the group ID is set to 0 (root group), the home directory is /root, and the shell for that user is /bin/bash. You can change the home directory or the shell used, if you like, by simply editing the values in this file.
Aliases for the rm, cp, and mv commands allow those commands to be run with the −i option. This prevents massive numbers of files being removed, copied, or moved by mistake. The −i option causes each deletion, copy, or move to prompt you before the actual change is made.

Saturday, January 3, 2009

Moving, copying, and deleting files

Commands for moving, copying, and deleting files are fairly straightforward. To change the location of a file, use the mv command. To copy a file from one location to another, use the cp command. To remove a file, use the rm command. Here are some examples:
$ mv abc def
$ mv abc ~
$ cp abc def
$ cp abc ~
$ rm abc
$ rm *
Of the two move (mv) commands, the first moves the file abc to the file def in the same directory (essentially renaming it), whereas the second moves the file abc to your home directory (~). The first copy command (cp) copies abc to the file def, whereas the second copies abc to you home directory (~). The first remove command (rm) deletes the abc file, whereas the second removes all the files in the current directory.

Friday, January 2, 2009

Understanding file permissions

After you’ve worked with Linux for a while, you are almost sure to get a Permission Denied message. Permissions associated with files and directories in Linux were designed to keep users from accessing other users’ private files and to protect important system files.
The nine bits assigned to each file for permissions define the access that you and others have to your file.
Permission bits appear as rwxrwxrwx. The first three bits apply to the owner’s permission, the next three apply to the owner’s group, and the last three apply to all others. The r stands for read, the w stands for write, and the x stands for execute permissions. If a dash appears instead of the letter, it means that permission is turned off for that associated read, write, or execute.
You can see the permission for any file or directory by typing the ls −ld command. The named file or directory appears as those shown in the example below:
$ ls −ld ch3 test
−rw−rw−r−− 1 chris sales 4983 Jan 18 22:13 ch3
drwxr−xr−x 2 chris sales 1024 Jan 24 13:47 test
The first line shows a file (ch3) that has read and write on for the owner and the group. All other users have read permission, which means they can view the file but cannot change its contents or remove it. The second line shows a directory (indicated by the letter d before the permission bits). The owner has read, write, and execute permission, while the group and other users have only read and execute permissions. As a result, only the owner can add, change, or delete files in that directory. Any other user, however, can only read the contents, change to that directory, and list the contents of the directory.
If you own a file, you can change the permission on it as you please. You can do this with the chmod command. For each of the three sets of permission on a file (read, write, and execute), the r is assigned to the number 4, w to 2, and x to 1. So to make permissions wide open for yourself as owner, you would set the first number to 7 (4 plus 2 plus 1). The same would be true for group and other permission. Any combination of permissions can result from 0 (no permission) through 7 (full permission).
Here are some examples of how to change permission on a file and what the resulting permission would be:
chmod 777 files -> rwxrwxrwx
chmod 755 files -> rwxr−xr−x
chmod 644 files -> rw−−r—−r−−
chmod 000 files -> −−−−−−−−−