手动添加用户:
1./etc/passwd 最后添加一行 lemon:x:520:520:LEMON:/home/lemon:/bin/bash
2./etc/shadow 最后添加一行 lemon::15249:0:99999:7::: (1 2 可用vipw)
3./etc/group 最后添加一行 lemon:x:520:
4./etc/gshadow 最后添加一行 lemon:!:: (3 4 可用vigr命令直接修改 )
5. mkdir /home/lemon 创建家目录
6. cp -f /etc/skel/.* /home/lemon
cp -rf /etc/skel/.mozilla /home/lemon 复制用户所需文件
7. chown -R lemon.lemon /home/lemon 修改 家目录所有权
shell脚本批量添加用户
#! /bin/sh
touch user.list
touch pwd.list
echo enter user name #输入用户名
read username
echo enter pwd # 输入用户密码
read pwd
echo "enter the user's number" #所需添加用户数目
read num
n=1
while [ $n -le $num ] #生成用户和密码列表
do
if [ $n -lt 10 ]
then
echo ""$username"00$n::60$n:60$n:"$username":/home/"$username"00$n:/bin/bash" >> user.list
echo ""$username"00$n:$pwd" >> pwd.list
n=$(( $n + 1 ))
elif [ $n -lt 100 ]
then
echo ""$username"0$n::6$n:6$n:"$username":/home/"$username"0$n:/bin/bash" >> user.list
echo ""$username"0$n:$pwd" >> pwd.list
n=$(( $n + 1 ))
fi
done
newusers < user.list
pwunconv
grpunconv
chpasswd < pwd.list
pwconv
grpconv
echo "user add OK"
批量删除用户
# !/bin/bash
echo "the username:"
read username
awk -F: '{ print $1 }' /etc/passwd | grep $username > duser.list
while read line
do
echo "===="
echo $line
userdel -r $line
groupdel $line
done < duser.list
echo "user del OK"
参考网址:
阅读(768) | 评论(0) | 转发(0) |