1)添加一个用户test1, 主目录为/tmp/test1,uid号为1006,全名为zhangsan,shell为/bin/csh
[root@canway01 ~]# useradd test1 -d /tmp/test1 -u 1006 -c zhangsan -s /bin/csh
[root@canway01 ~]# id test1
uid=1006(test1) gid=1006(test1) 组=1006(test1)
useradd参数说明:
-d 表示用户的主目录
-u 表示用户的UID
-c 表示用户的GECOS 字段
-s 表示用户的登录shell
2)将问题一中创建的用户test1的shell改为/bin/ash
[root@canway01 ~]# usermod test1 -s /bin/ash
[root@canway01 ~]# id test1
uid=1006(test1) gid=1006(test1) 组=1006(test1)
[root@canway01 ~]# cat /etc/passwd|grep test1
test1:x:1006:1006:zhangsan:/tmp/test1:/bin/ash
usermod参数说明:
-s 表示修改用户的登录shell
3)创建一个用户test2,要求test2用户只能通过ftp、mail、http等下载文件,但不能进行交互式登录。
[root@canway01 ~]# useradd test2 -s /sbin/nologin
[root@canway01 ~]# id test2
uid=1007(test2) gid=1007(test2) 组=1007(test2)
[root@canway01 ~]# cat /etc/passwd|grep test2
test2:x:1007:1007::/home/test2:/sbin/nologin
useradd参数说明:
-s /sbin/nologin 表示用户不能交互式登录
4)创建一个用户mysql,管理Linux中MySQL数据库,禁止其shell登录,且不创建用户的(家)主目录。
[root@canway01 ~]# useradd mysql -M -s /sbin/nologin
[root@canway01 ~]# id mysql
uid=1008(mysql) gid=1008(mysql) 组=1008(mysql)
[root@canway01 ~]# cat /etc/passwd|grep mysql
mysql:x:1008:1008::/home/mysql:/sbin/nologin
useradd参数说明:
-M 表示不创建用户的家目录
补充说明:此处-M和-s的顺序不能变,因为-s /sbin/nologin
作为一个整体存在,除非它整体与-M互换位置。
5)添加一个组work1,把用户test1添加到该组中。
[root@canway01 ~]# groupadd work1;usermod test1 -aG work1
[root@canway01 ~]# tail -1 /etc/group
work1:x:1009:test1
[root@canway01 ~]# tail -1 /etc/gshadow
work1:!::test1
usermod参数说明:
-G 表示新的附加组列表
-a 表示将用户追加至上边 -G 中提到的附加组中,并不从其它组中删除此用户