标签:linux用户与组
1、批量创建(zhangsan lisi wangwu)账号[root@zab ~]# vim f2
[root@zab ~]# 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
[root@zab ~]# newusers f2
[root@zab ~]# 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
[root@zab ~]# 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
[root@zab ~]# ls -a /home/wangwu
. .. ---- 无/etc/skel配置文件 需手动在home/wangwu配置skel下文件
wangwu为例:
[root@zab ~]# id wangwu
uid=555(wangwu) gid=555(wangwu) groups=555(wangwu)
[root@zab home]# cp -a /etc/skel/.[^.]* wangwu 如果家目录不存在[root@zab home]# cp -r /etc/skel wangwu
[root@zab 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
[root@zab home]# chown -R wangwu:wangwu wangwu ----修改wangwu权限属性
[root@zab 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、批量修改密码
[root@zab home]# cat /etc/shadow |tail -3
[root@zab 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::
[root@zab home]# vim f4
[root@zab home]# cat f4 ----/etc/shadow格式
zhangsan:qwe123:
lisi:qwe111:
wangwu:qwe222:
[root@zab home]# cat f4|chpasswd
[root@zab 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进行别名定义
[root@zab home]# alias rm='mv -t /app' ----mv [OPTION]... -t DIRECTORY SOURCE...
[root@zab home]# touch f5
[root@zab home]# rm f5
[root@zab home]# ls /app
f5 lost+found
总结:mv命令加上-t选项,使源文件放在后面,移动到前面的目录内。
标签:linux用户与组
原文地址:http://blog.51cto.com/13157015/2044454