class="22277">
这节描述你需要知道有些程式在安装时就已经有;Shadow;Suite。大部分的资讯在操作手册可以找到。;
7.1;新增、修改和删除使用者;
Shadow;Suite;新增下列指令用来新增、修改和删除使用者。;这也是可以安装;adduser;程式。;
useradd
useradd;使令可用在系统中新增使用者。;你也可以采用此指令来改变预设字串。;
你应该做的第一件事是检查预设值设定和针对你的系统进行改变:;
useradd;-D
--------------------------------------------------------------------------------
GROUP=1
HOME=/home
INACTIVE=0
EXPIRE=0
SHELL=
SKEL=/etc/skel
--------------------------------------------------------------------------------
预设值不全是你要的,所以如果你开始新增使用者,你必须详阅每个使用者资讯。而且,我们可能和应该改变设定值。;
在我的系统上:;
我要预设群组是;100;
我要密码每到;60;天就到期;
我不要锁住帐号因为密码会到期;
我要预设;shell;是;/bin/bash;
为了这些改变,我要使用:;
useradd;-D;-g100;-e60;-f0;-s/bin/bash
现在执行;useradd;-D;将得到:;
--------------------------------------------------------------------------------
GROUP=100
HOME=/home
INACTIVE=0
EXPIRE=60
SHELL=/bin/bash
SKEL=/etc/skel
--------------------------------------------------------------------------------
尽管依照你需要修改,预设值将存在;/etc/default/useradd.;
先在你可以使用;useradd;来新增系统使用者。举例说明,新增一使用者;fred;使用预设值方式如下:;
useradd;-m;-c;"Fred;Flintstone";fred
这将在;/etc/passwd;档中的一行建立如下:;
fred:*:505:100:Fred;Flintstone:/home/fred:/bin/bash
且在;/etc/shadow;档中的一行建立如下;;
fred:!:0:0:60:0:0:0:0
fred的根目录将被建立且;/etc/skel;的内容将被复制因为指令句中有;-m;设定。;
因为我们并未详述;UID,系统会直接寻找下一个可获得的编号。;
fred的帐号被建立罗,但是;fred;仍然不能签入直到我们不再锁住(unlock)这个帐号。透过更改密码完成;unlock;帐号,方法如下:;
passwd;fred
--------------------------------------------------------------------------------
Changing;password;for;fred□Enter;the;new;password;(minimum;of;5;characters)
Please;use;a;combination;of;upper;and;lower;case;letters;and;numbers.
New;Password:;*******
Re-enter;new;password:;*******
--------------------------------------------------------------------------------
现在;/etc/shadow;档将包含:;
fred:J0C.WDR1amIt6:9559:0:60:0:0:0:0
且;fred;将可以签入和使用该系统。;useradd;和其他附带;Shadow;Suite;比较好的地方是可以自动改变;/etc/passwd;和;/etc/shadow;。;所以如果你正在新增一个使用者,且另一个使用者正在更改密码,这两个操作都可以正确的执行。;
你使用提供的指令比直接存取;/etc/passwd;和;/etc/shadow;档还好。;如果你正编辑;/etc/shadow;档,且有个使用者在你编辑时要改变他的密码,然後你储存编辑结果,这个使用者的密码将会遗失掉。;
这里是使用;useradd;和;passwd;新增使用者的一些;interactive;script;:;
--------------------------------------------------------------------------------
#!/bin/bash
#
#;/sbin/newuser;-;A;script;to;add;users;to;the;system;using;the;Shadow
#;Suite's;useradd;and;passwd;commands.
#
#;Written;my;Mike;Jackson;
as;an;example;for;the;Linux
#;Shadow;Password;Howto.;;Permission;to;use;and;modify;is;expressly;granted.
#
#;This;could;be;modified;to;show;the;defaults;and;allow;modification;similar
#;to;the;Slackware;Adduser;program.;;It;could;also;be;modified;to;disallow
#;stupid;entries.;;(i.e.;better;error;checking).
#
##
#;;Defaults;for;the;useradd;command
##
GROUP=100#;Default;Group
HOME=/home;;;;;;;#;Home;directory;location;(/home/username)
SKEL=/etc/skel;;;#;Skeleton;Directory
INACTIVE=0;;;;;;;#;Days;after;password;expires;to;disable;account;(0=never)
EXPIRE=60#;Days;that;a;passwords;lasts
SHELL=/bin/bash;;#;Default;Shell;(full;path)
##
#;;Defaults;for;the;passwd;command
##
PASSMIN=0#;Days;between;password;changes
PASSWARN=14;;;;;;#;Days;before;password;expires;that;a;warning;is;given
##
#;;Ensure;that;root;is;running;the;script.
##
WHOAMI=`/usr/bin/whoami`
if;[;$WHOAMI;!=;"root";];;then
echo;"You;must;be;root;to;add;news;users!"
exit;1
fi
##
#;;Ask;for;username;and;fullname.
##
echo;""
echo;-n;"Username:;"
read;USERNAME
echo;-n;"Full;name:;"
read;FULLNAME
#
echo;"Adding;user:;$USERNAME."
#
#;Note;that;the;"";around;$FULLNAME;is;required;because;this;field;is
#;almost;always;going;to;contain;at;least;on;space,;and;without;the;"'s
#;the;useradd;command;would;think;that;you;we;moving;on;to;the;next
#;parameter;when;it;reached;the;SPACE;character.
#
/usr/sbin/useradd;-c"$FULLNAME";-d$HOME/$USERNAME;-e$EXPIRE;
-f$INACTIVE;-g$GROUP;-m;-k$SKEL;-s$SHELL;$USERNAME
##
#;;Set;password;defaults
##
/bin/passwd;-n;$PASSMIN;-w;$PASSWARN;$USERNAME;>/dev/null;2>&1
##
#;;Let;the;passwd;command;actually;ask;for;password;(twice)
##
/bin/passwd;$USERNAME
##
#;;Show;what;was;done.
##
echo;""
echo;"Entry;from;/etc/passwd:"
echo;-n;";;;"
grep;"$USERNAME:";/etc/passwd
echo;"Entry;from;/etc/shadow:"
echo;-n;";;;"
grep;"$USERNAME:";/etc/shadow
echo;"Summary;output;of;the;passwd;command:"
echo;-n;";;;"
passwd;-S;$USERNAME
echo;""
--------------------------------------------------------------------------------
新增使用者是用;script;比直接编辑;/etc/passwd;/;/etc/shadow;档或使用像;Slackware;的;adduser;程式还要好。;
需要更多;useradd;资讯请参照线上操作手册。;
usermod
usermod;程式是用在修改使用者资讯。它的参数使用和;useradd;程式类似。;
如果你要更新;fred;的;shell,你要作下列步骤:;
usermod;-s;/bin/tcsh;fred
现在;fred;的;/etc/passwd;档将变成:;
fred:*:505:100:Fred;Flintstone:/home/fred:/bin/tcsh
如果要使;fred;的帐号到期日为;09/15/97:;
usermod;-e;09/15/97;fred
现在;fred;在;/etc/shadow;的栏位变成:;
fred:J0C.WDR1amIt6:9559:0:60:0:0:10119:0
需要更多;usermod;资讯请参照线上操作手册。;
userdel
userdel;用在删除使用者,使用方法为:;
userdel;-r;username
-r;参数可以将该使用者根目录全部移除。位在期待目录的档案则需手动移除。;
如果你只是要简单的锁住帐号而没有要删除它,建议你使用;passwd;指令。;
7.2;passwd;指令和;passwd;老化;
passwd;指令很明显使用在改变密码,除此之外,可由;root;使用在:;
Lock;和;unlock;帐号;(-l;and;-u);
设定密码合法的最大天数;(-x);
设定密码改变间的最小天数;(-n);
设定密码到期的警告天数;(-w);
设定在帐号未被锁死密码到期後的警告天数;(-i);
允许查询帐号资讯;(-S);
举例说明,如果要锁死;fred;帐号:;
passwd;-S;fred
fred;P;03/04/96;0;60;0;0
这表示;fred;的密码是有效的,它在;03/04/96;被修改且任何时间都可被修改,;fred;将不会收到警告且帐号将不会因密码到期而关闭。;
这表示如果;fred;在密码到期後签入,它将被要求用一个新密码签入。;
如果我们决定要警告;fred;在密码过期前;14;天,且让它的帐号在到期後14天警告,我们需要作下列步骤:;
passwd;-w14;-i14;fred
现在;fred;改变为:;
fred;P;03/04/96;0;60;14;14
需要更多;passwd;资讯请参照线上操作手册。;
7.3;login.defs;档;
/etc/login;档是对;login;程式的;configuration;file;且;对;Shadow;Suite。;
/etc/login;包含从预设值密码改变的驱动设定。;
/etc/login.defs;档是一个很好的文件档,然而仍有些事情要注意:;
It;contains;flags;that;can;be;turned;on;or;off;that;determine;the;amount;of;logging;that;takes;place.;
It;contains;pointers;to;other;configuration;files.;
It;contains;defaults;assignments;for;things;like;password;aging.;
跟去上述你可以发现这是一个重要档,且你应该确认目前设定及你将对你系统的设