1、创建用户gentoo,附加组为bin和root,默认shell为 /bin/csh,注释信息为"Gentoo Distribution" 

[root@localhost ~]# useradd gentoo -G bin,root -s /bin/csh -c "Gentoo Distribution"

2、创建下面的用户、组和组成员关系 

名字为admins 的组 

[root@localhost ~]# groupadd admins

用户natasha,使用admins 作为附属组 

[root@localhost ~]# useradd natasha -G admins

用户harry,也使用admins 作为附属组 

[root@localhost ~]# useradd harry -G admins

用户sarah,不可交互登录系统,且不是admins 的成员。

[root@localhost ~]# useradd sarah -s /sbin/nologin

natasha,harry,sarah密码都是centos

[root@localhost home]# echo centos | passwd --stdin natasha
[root@localhost home]# echo centos | passwd --stdin harry
[root@localhost home]# echo centos | passwd --stdin sarah

3、创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser

[root@localhost ~]# useradd testuser -u 1234 -g bin -G root,ftp -s /bin/csh -d /home/testdir/

4、修改testuser uid:4321,主组:root,辅助组:nobody,loginname:test,home:/home/test 家数据迁移

[root@localhost home]# usermod -u 4321 -g root -G nobody -l test -m -d /home/test testuser

6、批量创建帐号:user1...user10

uid:3000-3009,shell:/bin/csh,home:/testdir/username

[root@localhost home]# cat user.txt
user1:x:3001:3001::/testdir/user1:/bin/csh
user2:x:3002:3002::/testdir/user2:/bin/csh
user3:x:3003:3003::/testdir/user3:/bin/csh
user4:x:3004:3004::/testdir/user4:/bin/csh
user5:x:3005:3005::/testdir/user5:/bin/csh
user6:x:3006:3006::/testdir/user6:/bin/csh
user7:x:3007:3007::/testdir/user7:/bin/csh
user8:x:3008:3008::/testdir/user8:/bin/csh
user9:x:3009:3009::/testdir/user9:/bin/csh
[root@localhost home]# cat pass.txt
user1:user1pass
user2:user2pass
user3:user3pass
user4:user4pass
user5:user5pass
user6:user6pass
user7:user7pass
user8:user8pass
user9:user9pass
[root@localhost home]# newusers user.txt
[root@localhost home]# cat pass.txt | chpasswd

注意家目录相关配置,使用户正常登录

如果家目录缺少默认文件,可以在拷贝/etc/skel/目录下的文件。修改权限即可。