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) |
總結
以上是生活随笔為你收集整理的linux shadow 时间,Linux Shadow-Password-HOWTO - 7. 将 Shadow Suite 放进来使用(1)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 环形时间显示_使用Ard
- 下一篇: Linux上的JAVA的IDE,在lin