linux shadow 时间,Linux Shadow-Password-HOWTO - 7. 将 Shadow Suite 放进来使用(1)

这节描述你需要知道有些程式在安装时就已经有 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 ""

【责编:admin】

--------------------next---------------------

阅读(195) | 评论(0) | 转发(0) |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值