rhl39.htm
来自「linux的初学电子书」· HTM 代码 · 共 1,340 行 · 第 1/4 页
HTM
1,340 行
Used for system processes. This login is used only to own the processes and set their permissions properly.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
bin
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Owns executables.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
sys
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Owns executables.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
adm
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Owns accounting and log files.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
uucp
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Used for UUCP communication access and files.</FONT>
</TABLE><P>The other system logins are used for specific purposes (postmaster for mail, and so on) that are usually self-explanatory. You should not change any of the system logins. In most cases, they have an asterisk in the password field preventing
their use for entry purposes.
<BR>
<BR>
<A NAME="E68E335"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Adding Users</B></FONT></CENTER></H3>
<BR>
<P>There are two ways to add users to your system: manually edit the /etc/passwd file, or use an automated script that prompts you for the new user's details and writes a new line to the /etc/passwd file for you. The automated approach is handy for new
system administrators who are uneasy about editing a file as important as /etc/passwd, or for those occasions when you have to add several users and the risk of error is thus increased. You must modify the /etc/passwd file when you are logged in as root.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Before making changes to your /etc/passwd file, make a copy of it! If you corrupt the /etc/passwd file you will not be able to log in, even as root, and your system is effectively useless except in system administration mode. Keep a copy of the
/etc/passwd file on your emergency floppy or boot floppy in case of problems.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>To add an entry to the /etc/passwd file, use any editor that saves information in ASCII. Add the new users to the end of the file, using a new line for each user. Make sure you use a unique user name and user ID (UID) for each user. For example, to add
a new user called bill to the system with a UID of 103 (remember to keep UIDs sequential for convenience) and a GID of 100 (the default group), a home directory of /home/bill, and a startup shell of the Bourne shell, add the following line to the
/etc/passwd file:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">bill::103:100:Bill Smallwood:/home/bill:/bin/sh</FONT></PRE>
<P>Note that we have left the password blank because you can't type in an encrypted password yourself. As soon as you have saved the changes to /etc/passwd, set a password for this account by running the command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">passwd bill</FONT></PRE>
<P>This command prompts you for an initial password. Set the password to something that Bill will be able to use, and ask him to change the password the first time he works on the system. Many system administrators set the initial password to a generic
string (such as "password" or the login name) and then force the new user to change the password the first time they log in. Using generic strings is usually acceptable if the user logs in quickly, but don't leave accounts with generic login
strings sitting around too long—someone else may use the account.
<BR>
<P>After you have added the necessary line to the /etc/passwd file, you should create the user's home directory. Once created, you must set the ownership to have that user own the directory. For the preceding example, you would issue the following
commands:
<BR>
<PRE>
<FONT COLOR="#000080">mkdir /home/bill
chown bill /home/bill</FONT></PRE>
<P>All users must belong to a group. If your system has only one group defined, then add the user's user name to the line in the /etc/group file that represents that group. If the new user should belong to several groups, add the user name to each group in
the /etc/group file. The /etc/group file and groups in general are discussed in the "Groups" section later in the chapter.
<BR>
<P>Finally, the configuration files for the users' shells should be copied into their home directory and set to allow them access for customization. For example, if you copy the Bourne shell's .profile file from another user called yvonne, you would issue
the following commands:
<BR>
<PRE>
<FONT COLOR="#000080">cp /home/yvonne/.profile /home/bill/.profile
chown bill /home/bill/.profile</FONT></PRE>
<P>You should also manually check the configuration file to ensure there are no environment variables that will be incorrectly set when the user logs in. For example, there may be a line defining the HOME environment variable or the spool directories for
printer and mail. Use any ASCII editor to check the configuration file. If you are using the Korn or C shell, there are other configuration files that need to be copied over and edited. Bourne shell compatibles need only a .profile, while the C shell and
compatibles need .login and .cshrc. The Korn shell and compatibles need a .profile and usually another file with environment variables embedded in it.
<BR>
<P>In general, the process for manually adding a new user to your system is:
<BR>
<OL>
<LI>Add an entry for the user in the /etc/passwd file.
<BR>
<BR>
<LI>Create the user's home directory and set the ownership.
<BR>
<BR>
<LI>Copy the shell startup files and edit their settings and ownerships.
<BR>
<BR>
</OL>
<P>The command vipw invokes the vi editor (or whatever the default system editor has been set to) and edits a temporary copy of the /etc/passwd file. The use of a temporary file and file lock acts as a lock mechanism to prevent two different users from
editing the file at the same time. When the file is saved, vipw does a simple consistency check on the changed file, and if all appears proper, the /etc/passwd file is updated.
<BR>
<P>The automated scripts for Linux tend to have the names useradd or adduser. When run, they prompt you for all the information that is necessary in the /etc/passwd file. Both versions let you exit at any time to avoid changing the /etc/passwd file. The
automated scripts also tend to ask for an initial password, which you can set to anything you want or leave blank. One advantage of the automated scripts is that they copy all the configuration files for the supported shells automatically, and in some
cases, make environment variable changes for you. This can significantly simplify the process of adding users.
<BR>
<P>A quick note on passwords—they are vitally important to the security of your system. Unless you are on a standalone Linux machine with no dial-in modems, every account should have a secure password. Passwords are assigned and changed with the
passwd command. The superuser can change any password on the system, but a user can only change his own password.
<BR>
<BR>
<A NAME="E68E336"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Deleting Users</B></FONT></CENTER></H3>
<BR>
<P>Just like adding new users, deleting users can be done with an automated script or manually. The automated scripts deluser or userdel asks which user you want to delete, and then removes the entry from the /etc/passwd file. Some scripts also clean out
the spool and home directory files, if you want. You must make any deletions to the /etc/passwd file when logged in as root.
<BR>
<P>If you delete users manually, simply remove their entries from the /etc/passwd file. Then you can clean up their directories to clear disk space. You can completely delete all their files and their home directory with the command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">rm -r -f /home/userdir</FONT></PRE>
<P>where /home/userdir is the full pathname of the user's home directory. Make sure there are no files you want to keep in that directory before you blow them all away!
<BR>
<P>Next, you should remove the user's mail spool file, which is usually kept in /usr/spool/mail/username. For example, to remove the user walter's mail file, issue the command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">rm /usr/spool/mail/walter</FONT></PRE>
<P>The spool file is a single file, so this command cleans up the entries properly. To finish off the mail clean-up, check that the user has no entries in the mail alias files (usually /etc/aliases) or you can force all mail for that user to another login
(such as root). To make any changes to the /etc/aliases file effective, you must run the newaliases command.
<BR>
<P>Finally, clean up the user's cron and at jobs. You can display the user's crontab file using the crontab command.
<BR>
<P>If you need to retain the user for some reason (such as file ownerships, a general access account, or accounting purposes), you can disable the login completely by placing an asterisk in the password field of the /etc/passwd file. That login can never
be used once an asterisk is in the password field. If you need to reactivate the account, simply run the passwd command.
<BR>
<P>The process for manually deleting a user (or using an automated script that doesn't clean up directories and files) is:
<BR>
<OL>
<LI>Remove the user's entry from /etc/passwd and /etc/group.
<BR>
<BR>
<LI>Remove the user's mail file and any mail aliases.
<BR>
<BR>
<LI>Remove any cron or at jobs.
<BR>
<BR>
<LI>Remove the home directory if you don't want any files it holds.
<BR>
<BR>
</OL>
<P>Occasionally, you may want to temporarily disable a user's account, such as when he or she goes on extended leave, vacation, or because you are mad at them! If you want to temporarily disable the login but be able to recover it at any time in the
future, add an asterisk as the first character of the encrypted password. Don't alter any characters in the existing password, but just add the asterisk to the front. When you want to reactivate the account, remove the asterisk and the password is back to
whatever it was set at before you made the changes.
<BR>
<BR>
<A NAME="E68E337"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Groups</B></FONT></CENTER></H3>
<BR>
<P>Every user on a UNIX and Linux system belongs to a group. A group is a collection of individuals lumped together for some reason. The users in a group may all work in the same department, may need access to a particular programming utility, or they may
all have access to use a special device, such as a scanner or color laser printer. Groups can be set up for any reason, and users can belong to any number of groups. However, a user can only be a member of one group at a time, because groups are used for
determining file permissions and Linux only allows one group ID per user at any point in time.
<BR>
<P>Groups can have their permissions set so that members of that group have access to devices, files, file systems, or entire machines that other users who do not belong to that group may be restricted from. For example, this can be useful when you have an
accounting department, all members of which need access to the company's accounts. However, you wouldn't want non-accounting people to go snooping through financial statements, so creating a special group that has access to the accounting system makes
sense.
<BR>
<P>Many small Linux systems have only one group, the default group, because that is the simplest way to manage a system. Then, each user's access to devices and files is controlled by the devices' or files' permissions, not the group. When you start to get
several different users in logical groupings, though, groups start to make more sense. You can even use groups to control your friends' or children's access to areas on your home Linux system.
<BR>
<P>Group information is maintained in the file /etc/group, which is similar in layout to the /etc/passwd file. The default /etc/group file from a newly installed Linux system is shown in Listing 39.2.
<BR>
<P>
<FONT COLOR="#000080"><B>Listing 39.2. The default </B><B>/etc/group</B><B> file.</B></FONT>
<BR>
<PRE>
<FONT COLOR="#000080">root::0:root
bin::1:root,bin,daemon
daemon::2:root,bin,daemon
sys::3:root,bin,adm
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?