标签:用户管理
1 、创建用户gentoo ,附加组为bin 和root ,默认shell为/bin/csh ,注释信息为"Gentoo Distribution"
[root@localhost ~]# useradd -G bin,root -c "Gentoo Distribution" -s /etc/csh gentoo useradd: user ‘gentoo‘ already exists [root@localhost ~]# groups gentoo;grep gentoo /etc/passwd gentoo : gentoo root bin gentoo:x:501:501:Gentoo Distribution:/home/gentoo:/etc/csh
2 、创建 下面的用户、组和组成员关系
名字为为admins 的组
用户natasha ,使用admins 作为附属组;用户harry ,也使用admins 作为附属组
用户sarah ,不可交互登录系统, 且不是admins 的成员,natasha ,harry ,sarah 密码 都是centos
[root@localhost ~]# groupadd admins [root@localhost ~]# useradd -G admins natasha;useradd -G admins harry [root@localhost ~]# id natasha;id harry uid=502(natasha) gid=503(natasha) groups=503(natasha),502(admins) uid=503(harry) gid=504(harry) groups=504(harry),502(admins)
[root@localhost ~]# useradd -s /sbin/nologin sarah [root@localhost ~]# grep sarah /etc/passwd sarah:x:504:505::/home/sarah:/sbin/nologin
[root@localhost ~]# echo "centos" | passwd --stdin natasha Changing password for user natasha. passwd: all authentication tokens updated successfully. [root@localhost ~]# echo "centos" | passwd --stdin harry Changing password for user harry. passwd: all authentication tokens updated successfully. [root@localhost ~]# echo "centos" | passwd --stdin sarah Changing password for user sarah. passwd: all authentication tokens updated successfully.
3、创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser
[root@localhost ~]# useradd -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser testuser [root@localhost ~]# id testuser;grep testuser /etc/passwd uid=1234(testuser) gid=1(bin) groups=1(bin),0(root),50(ftp) testuser:x:1234:1::/testdir/testuser:/bin/csh
4、修改testuser uid:4321,主组:root,辅助组:nobody,loginname:test,home:/home/test
家数据迁移
[root@localhost ~]# usermod -u 4321 -g root -G nobody -l test -d /home/test -m testuser [root@localhost ~]# id test;grep test /etc/passwd uid=4321(test) gid=0(root) groups=0(root),99(nobody) test:x:4321:0::/home/test:/bin/csh
5、批量创建帐号:user1...user10
uid:3000-3009,shell:/bin/csh,home:/testdir/username
passwd:usernamepass
注意家目录相关配置,使用户正常登录
[root@localhost ~]# cat user.txt user1::3001:::/testdir/user1:/bin/csh user2::3002:::/testdir/user2:/bin/csh user3::3002:::/testdir/user3:/bin/csh user4::3003:::/testdir/user4:/bin/csh user5::3004:::/testdir/user5:/bin/csh user6::3005:::/testdir/user6:/bin/csh user7::3006:::/testdir/user7:/bin/csh user8::3007:::/testdir/user8:/bin/csh user9::3008:::/testdir/user9:/bin/csh user10::3009:::/testdir/user10:/bin/csh
[root@localhost ~]# newusers user.txt [root@localhost ~]# tail -10 /etc/passwd user1:x:3001:3001::/testdir/user1:/bin/csh user2:x:3002:3002::/testdir/user2:/bin/csh user3:x:3002:3003::/testdir/user3:/bin/csh user4:x:3003:3004::/testdir/user4:/bin/csh user5:x:3004:3005::/testdir/user5:/bin/csh user6:x:3005:3006::/testdir/user6:/bin/csh user7:x:3006:3007::/testdir/user7:/bin/csh user8:x:3007:3008::/testdir/user8:/bin/csh user9:x:3008:3009::/testdir/user9:/bin/csh user10:x:3009:3010::/testdir/user10:/bin/csh
[root@localhost ~]# cat pss.txt user1:user1pss user2:user2pss user3:user3pss user4:user4pss user5:user5pss user6:user6pss user7:user7pss user8:user8pss user9:user9pss user10:user10pss
[root@localhost ~]# cat pss.txt | chpasswd
[root@localhost ~]# cp /etc/skel/.[^.]* /testdir/user1
...
...
标签:用户管理
原文地址:http://suifengsky.blog.51cto.com/11393684/1833351