• Linux用户管理


    问题一

    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)
    
    • 1
    • 2
    • 3

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5

    usermod参数说明:
    -G 表示新的附加组列表
    -a 表示将用户追加至上边 -G 中提到的附加组中,并不从其它组中删除此用户

  • 相关阅读:
    【软件测试】资深测试聊一聊,测试架构师是怎么样的,做一名成功的测试工程师......
    信息系统项目管理师必背核心考点(七十三)黑/白/灰盒测试
    mysql高手进阶优化篇
    hadoop集群安装(四):安装hadoop集群
    第09章 循环神经网络变种
    电力系统iec103通信
    RK3588 linux内核中断之上半部(二)
    为什么越来越多的开发者放弃使用Postman,而选择Eolink?
    HTML入门
    科学素养题(2022年2月-2022年10月)
  • 原文地址:https://blog.csdn.net/oldboy1999/article/details/127755761