批量创建用户账号和自定义回收站
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量创建用户账号和自定义回收站相关的知识,希望对你有一定的参考价值。
1、批量创建(zhangsan lisi wangwu)账号[[email protected] ~]# vim f2
[[email protected] ~]# cat f2
zhangsan:x:560:560::/home/zhangsan:/bin/bash ----/tec/passwd格式
lisi:x:550:550::/home/lisi:/bin/bash
wangwu:x:555:555::/home/wangwu:/bin/bash
[[email protected] ~]# newusers f2
[[email protected] ~]# getent passwd | tail -n3
zhangsan:x:560:560::/home/zhangsan:/bin/bash
lisi:x:550:550::/home/lisi:/bin/bash
wangwu:x:555:555::/home/wangwu:/bin/bash
[[email protected] ~]# ll /home
total 16
drwx------. 2 622 622 4096 Jul 24 11:09 lisi
drwx------. 2 wangwu wangwu 4096 Jul 24 11:18 wangwu
drwx------. 2 522 522 4096 Jul 24 11:09 zhangsan
[[email protected] ~]# ls -a /home/wangwu
. .. ---- 无/etc/skel配置文件 需手动在home/wangwu配置skel下文件
wangwu为例:
[[email protected] ~]# id wangwu
uid=555(wangwu) gid=555(wangwu) groups=555(wangwu)
[[email protected] home]# cp -a /etc/skel/.[^.]* wangwu 如果家目录不存在[[email protected] home]# cp -r /etc/skel wangwu
[[email protected] home]# ll -a wangwu 或者mkdir -m 755 wang 创建并指明文件属性
total 32
drwx------. 5 wangwu wangwu 4096 Jul 24 11:41 .
drwxr-xr-x. 6 root root 4096 Jul 24 11:18 ..
-rw-r--r--. 1 root root 18 Mar 23 08:15 .bash_logout
-rw-r--r--. 1 root root 176 Mar 23 08:15 .bash_profile
-rw-r--r--. 1 root root 124 Mar 23 08:15 .bashrc
drwxr-xr-x. 2 root root 4096 Nov 12 2010 .gnome2
drwxr-xr-x. 4 root root 4096 Jul 11 21:49 .mozilla
drwxr-xr-x. 4 root root 4096 Jul 24 11:37 skel
[[email protected] home]# chown -R wangwu:wangwu wangwu ----修改wangwu权限属性
[[email protected] home]# ll -a wangwu
total 32
drwx------. 5 wangwu wangwu 4096 Jul 24 11:41 .
drwxr-xr-x. 6 root root 4096 Jul 24 11:18 ..
-rw-r--r--. 1 wangwu wangwu 18 Mar 23 08:15 .bash_logout
-rw-r--r--. 1 wangwu wangwu 176 Mar 23 08:15 .bash_profile
-rw-r--r--. 1 wangwu wangwu 124 Mar 23 08:15 .bashrc
drwxr-xr-x. 2 wangwu wangwu 4096 Nov 12 2010 .gnome2
drwxr-xr-x. 4 wangwu wangwu 4096 Jul 11 21:49 .mozilla
drwxr-xr-x. 4 wangwu wangwu 4096 Jul 24 11:37 skel
:如果一主机账户往另一主机迁移,可以用getent /etc/passwd username>f1 用scp命令将f1传入另一主机 ,执行newusers f1 并将/etc/skel下文件复制到各自home下的家目录下
2、批量修改密码
[[email protected] home]# cat /etc/shadow |tail -3
[[email protected] home]# getent shadow|tail -3
zhangsan:$6$E6B60/L4QLm/$QRvHhvzO913b9lKiAB.eS0Xnc0pRiIKGrj6Qb9PTCR0ewZToEigR2SnymXGzx0s3DK.CpnYeQsOGGEPsj4sZD0:17371:0:99999:7:::
lisi:$6$5EXlM/T9JmK/sD$rAuvVydrapeWcSNMi3MCk.X7S3PUUG5OmiU1PxFYbuYB2l4LPvhXcaS0dFfHkLBHkoNIKzq4Yx48VeMlaOJo8/:17371:0:99999:7:::
wangwu:$6$vZ42Ltw2V$pbrHI27HeUNcQDZqBCKjzDoassIapo.Q7cq0m.SshelO8AR1xwSmFAlnyV9I3uGxy.u3/s71Betm.jRo3ysVl0:17371:0:99999:7::
[[email protected] home]# vim f4
[[email protected] home]# cat f4 ----/etc/shadow格式
zhangsan:qwe123:
lisi:qwe111:
wangwu:qwe222:
[[email protected] home]# cat f4|chpasswd
[[email protected] home]# getent shadow|tail -3
zhangsan:$6$E6B60/L4QLm/$QRvHhvzO913b9lKiAB.eS0Xnc0pRiIKGrj6Qb9PTCR0ewZToEigR2SnymXGzx0s3DK.CpnYeQsOGGEPsj4sZD0:17371:0:99999:7:::
lisi:$6$5EXlM/T9JmK/sD$rAuvVydrapeWcSNMi3MCk.X7S3PUUG5OmiU1PxFYbuYB2l4LPvhXcaS0dFfHkLBHkoNIKzq4Yx48VeMlaOJo8/:17371:0:99999:7:::
wangwu:$6$vZ42Ltw2V$pbrHI27HeUNcQDZqBCKjzDoassIapo.Q7cq0m.SshelO8AR1xwSmFAlnyV9I3uGxy.u3/s71Betm.jRo3ysVl0:17371:0:99999:7:::
3、对rm命令定义回收站
避免误删除对rm进行别名定义
[[email protected] home]# alias rm='mv -t /app' ----mv [OPTION]... -t DIRECTORY SOURCE...
[[email protected] home]# touch f5
[[email protected] home]# rm f5
[[email protected] home]# ls /app
f5 lost+found
总结:mv命令加上-t选项,使源文件放在后面,移动到前面的目录内。
以上是关于批量创建用户账号和自定义回收站的主要内容,如果未能解决你的问题,请参考以下文章