📄 0308-0310.html
字号:
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311623:SAMS TEACH YOURSELF LINUX IN 24 HOURS:Basic System Administration</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311623 //-->
<!-- TITLE=SAMS TEACH YOURSELF LINUX IN 24 HOURS //-->
<!-- AUTHOR=BILL BALL, STEPHEN SMOOGEN //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=20 //-->
<!-- PAGES=0291-0312 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0305-0307.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0311-0312.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-308"><P>Page 308</P></A>
<P>
management using the su command. There are several ways to create new users in
Linux, but this section shows you the easy way, using a trio of commands:
adduser, passwd, and chfn.
</P>
<P>The first step in creating a new user is to use the
adduser command, found under the /usr/sbin directory. You must be the root operator to run this program:
</P>
<!-- CODE SNIP //-->
<PRE>
# adduser
Only root may add users to the system.
</PRE>
<!-- END CODE SNIP //-->
<P>The adduser program also requires you to specify a user name on the command line,
for example:
</P>
<!-- CODE //-->
<PRE>
# adduser cloobie
Looking for first available UID... 502
Looking for first available GID... 502
Adding login: cloobie...done.
Creating home directory: /home/cloobie...done.
Creating mailbox: /var/spool/mail/cloobie...done.
Don't forget to set the password.
</PRE>
<!-- END CODE //-->
<P>The command will create an account, assign a user identification (UID), a
group identification (GID), and then create a directory called
cloobie under the /home directory. As a reminder, the
adduser program tells you to set a password for your new user.
</P>
<H4><A NAME="ch20_ 21">
Changing Passwords in /etc/passwd with the passwd Command
</A></H4>
<P>After creating your new user, you must assign a password with the
passwd command. This command will create an entry in the
passwd text database in the /etc directory. To show
you how this works, the following example shows you the
passwd file, creates a password for your new user, and then shows you the password file so you can see the new entry.
</P>
<!-- CODE //-->
<PRE>
# cat /etc/passwd
root:syvolaPd3M4QE:0:0:root:/root:/bin/bash
bin:*:1:1:bin:/bin:
daemon:*:2:2:daemon:/sbin:
adm:*:3:4:adm:/var/adm:
lp:*:4:7:lp:/var/spool/lpd:
sync:*:5:0:sync:/sbin:/bin/sync
shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown
halt:*:7:0:halt:/sbin:/sbin/halt
mail:*:8:12:mail:/var/spool/mail:
news:*:9:13:news:/var/spool/news:
uucp:*:10:14:uucp:/var/spool/uucp:
operator:*:11:0:operator:/root:
games:*:12:100:games:/usr/games:
gopher:*:13:30:gopher:/usr/lib/gopher-data:
ftp:*:14:50:FTP User:/home/ftp:
nobody:*:99:99:Nobody:/:
bball:ODyJ5x09iRgNQ:500:500:Billy Ball,,,,:/home/bball:/bin/bash
</PRE>
<!-- END CODE //-->
<A NAME="PAGENUM-309"><P>Page 309</P></A>
<!-- CODE SNIP //-->
<PRE>
cloobie:*:502:502:RHS Linux User:/home/cloobie:/bin/bash
</PRE>
<!-- END CODE SNIP //-->
<P>You can see that although an account has been created, and contains a
username, UID, PID, name, directory, and default shell, there's no password. To add a password, type
the command, along with the new user's name:
</P>
<!-- CODE SNIP //-->
<PRE>
# passwd cloobie
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully
</PRE>
<!-- END CODE SNIP //-->
<P>You'll be asked for a password, and then asked to retype it to verify. If all goes well,
the password will be recorded in /etc/passwd, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
cloobie:9Qa4.uFMhmInA:502:502:RHS Linux User:/home/cloobie:/bin/bash
</PRE>
<!-- END CODE SNIP //-->
<P>Later on, users can change their own password by using the
passwd command, and you should encourage frequent password changes.
</P>
<P>
<CENTER>
<TABLE BGCOLOR="#FFFF99">
<TR><TD><B>
CAUTION
</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
As the sysadmin, you can change anyone's password if they forget it.
Don't forget yours!
</BLOCKQUOTE></TD></TR>
</TABLE></CENTER>
</P>
<P>Finally, you'll also want to use the chfn command to enter formal information about
users, or have your users enter this information. The
chfn command will ask
</P>
<!-- CODE //-->
<PRE>
# chfn cloobie
Changing finger information for cloobie.
Name [RHS Linux User]: Mr. Cloobie Doo
Office []: 400 Pennsylvania Ave.
Office Phone []: 202-555-1212
Home Phone []: 202-555-4000
Finger information changed.
</PRE>
<!-- END CODE //-->
<P>If you now examine the /etc/passwd entry, you'll see
</P>
<!-- CODE SNIP //-->
<PRE>
cloobie:9Qa4.uFMhmInA:502:502:Mr. Cloobie Doo,400 Pennsylvania Ave.,
202-555-1212,202-555-4000,:/home/cloobie:/bin/bash
</PRE>
<!-- END CODE SNIP //-->
<P>This information is used by the finger command. The formal name may also
be used along with the user name in mail messages, for example:
</P>
<!-- CODE //-->
<PRE>
# finger cloobie
Login: cloobie Name: Mr. Cloobie Doo
Directory: /home/cloobie Shell: /bin/bash
Office: 400 Pennsylvania Ave. Office Phone: 202-555-1212
Home Phone: 202-555-4000
Never logged in.
No mail.<BR>
</PRE>
<!-- END CODE //-->
<A NAME="PAGENUM-310"><P>Page 310</P></A>
<!-- CODE SNIP //-->
<PRE>
No Plan.
</PRE>
<!-- END CODE SNIP //-->
<P>The finger command will extract the user's information from the
/etc/passwd file and print it in a nice format. One of the other things you should note in a user's
/etc/passwd entry is the name of a shell at the end. This can be a unique way to not only specify the type of
shell used (your Linux system is set up to assign the bash shell by default), but to restrict the
user to a particular program.
</P>
<H4><A NAME="ch20_ 22">
Restricting Logins
</A></H4>
<P>Your users normally can change the shell used after login through the
chsh command. You can list the currently available shells by using the
chsh command's -l (list shells) option, for example:
</P>
<!-- CODE //-->
<PRE>
# chsh -l
/bin/ash
/bin/bsh
/bin/bash
/bin/sh
/bin/csh
/bin/ksh
/bin/tcsh
</PRE>
<!-- END CODE //-->
<P>The chsh command looks in a file called shells under the
/etc directory, and prints a list. This does not mean that these shells are available, just "acceptable." You can edit this file,
adding or removing shells that can be specified by your users. You should make sure that the
shells listed in this file are available on your system. To change shells, you can type
</P>
<!-- CODE SNIP //-->
<PRE>
# chsh -s /bin/ksh
Changing shell for root.
Shell changed.
</PRE>
<!-- END CODE SNIP //-->
<P>You can also use the chsh command to specify a program, other than a
shell, to use as the program run when the user logs in, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# chsh -s /usr/bin/pico cloobie
Changing shell for cloobie.
Warning: "/usr/bin/pico" is not listed as a valid shell.
Shell changed.
</PRE>
<!-- END CODE SNIP //-->
<P>The chsh program will complain if the program is not listed as a shell in the
/etc/shells file. Then check to see if the change was made:
</P>
<!-- CODE //-->
<PRE>
# cat /etc/passwd
...
cloobie:9Qa4.uFMhmInA:502:502:Mr. Cloobie Doo,400 Pennsylvania Ave.,
202-555-1212,202-555-4000,:/home/cloobie:/usr/bin/pico
</PRE>
<!-- END CODE //-->
<P>The preceding example specified the text editor
pico, which would allow a user to do word processing, printing, or spell-checking of documents, but that's all! As soon as the user
logs into Linux, the user is right in the text editor. After quitting the text editor, the user is
logged out. This is a handy technique you can use to restrict users, especially children, if you
only
</P>
<P><CENTER>
<a href="0305-0307.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0311-0312.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -