• centos 7.2 常用命令useradd的使用


    [备注1: 命令:id 用户名  //查看用户的信息, 例如id www]

    【备注2: /etc/group 系统的用户组存储地方, 查找指定用户组名是否存在,如:cat /etc/group | grep www】

    【备注3: /etc/passwd 系统的用户存储地方, cat /etc/passwd | grep www】

    1. useradd/adduser:两者相同,都是增加一个新的用户账号

    注意:用户名必须是唯一的名字,以下是增加一个tecmint用户

    [root@tecmint ~]# useradd tecmint

    以上命令用户为锁状态,必须为其解锁

    [root@tecmint ~]# passwd tecmint
    Changing password for user tecmint.
    New UNIX password:
    Retype new UNIX password:
    passwd: all authentication tokens updated successfully.

    此时将保存一个用户信息到/etc/passwd/文件中,文件内容为:

    tecmint:x:504:504:tecmint:/home/tecmint:/bin/bash

    分别显示为:用户、密码、UID号、GID号、用户信息、home目录、shell脚本。

    2.创建一个特定的/home目录用户;以下新用户是:anusha

    [root@tecmint ~]# useradd -d /data/projects anusha
    [root@tecmint ~]# cat /etc/passwd | grep anusha
    anusha:x:505:505::/data/projects:/bin/bash

    3.创建一个特定ID号用户:注意:0-为系统根用户,1-100为内部使用。

    注意:用户id唯一性

    [root@tecmint ~]# useradd -u 999 navin
    [root@tecmint ~]# cat /etc/passwd | grep tecmint
    navin:x:999:999::/home/navin:/bin/bash

    4.创建一个特定组ID号用户:每一个用户都有一个自己的GID;

    使用  -g 来指定j自己的id号

    [root@tecmint ~]# useradd -u 1000 -g 500 tarunika

    ‘/etc/passwd‘ 文件内容如下

    [root@tecmint ~]# cat /etc/passwd | grep tarunika
    tarunika:x:1000:500::/home/tarunika:/bin/bash

    5.增加用户到多个组:-G 选项指定多个组,分别用“,”分开

    例:增加用户"tecmint"到 admins, webadmin and developer组.

    [root@tecmint ~]# useradd -G admins,webadmin,developers tecmint

     用 id 命令查看

    [root@tecmint ~]# id tecmint
    uid=1001(tecmint) gid=1001(tecmint)
    groups=1001(tecmint),500(admins),501(webadmin),502(developers)
    context=root:system_r:unconfined_t:SystemLow-SystemHigh

    6.使用 -M选项增加没有 Home目录的用户:home目录为根的home目录。

    [root@tecmint ~]# useradd -M shilpi
    [root@tecmint ~]# ls -l /home/shilpi
    ls: cannot access /home/shilpi: No such file or directory

    7.用-e选项,创建一个终止日期的用户;缺省为:0--既永远。

    [root@tecmint ~]# useradd -e 2014-03-27 aparna

    可以用change命令改变用户口令和终止日期

    [root@tecmint ~]# chage -l aparna
    Last password change						: Mar 28, 2014
    Password expires						: never
    Password inactive						: never
    Account expires							: Mar 27, 2014
    Minimum number of days between password change		        : 0
    Maximum number of days between password change		        : 99999
    Number of days of warning before password expires		: 7

    8.创建一个口令终止日期用户

    以下是口令45天到期的用户

    [root@tecmint ~]# useradd -e 2014-04-27  45 tecmint

    9.使用-c选项增加注释:如完整名、电话等到/etc/passwd 文件中。

    [root@tecmint ~]# useradd -c "Manis Khurana" mansi
    [root@tecmint ~]# tail -1 /etc/passwd
    mansi:x:1006:1008:Manis Khurana:/home/mansi:/bin/sh

    10.使用-s选项改变用户的登陆shell:

    [root@tecmint ~]# useradd -s /sbin/nologin tecmint
    [root@tecmint ~]# tail -1 /etc/passwd
    tecmint:x:1002:1002::/home/tecmint:/sbin/nologin

    11. 增加一个特定 Home 目录、缺省shell 、注释的用户,例:ravi用户

    [root@tecmint ~]# useradd -m -d /var/www/ravi -s /bin/bash -c "TecMint Owner" -U ravi

     ‘-m -d‘ 选项建立特定 home 目录、‘-s‘ 选项设置缺省  shell 、‘-c‘ 选项 增加用户额外信息 、 ‘-U大写‘ 创建/增加相同名字的用户和组

    12. 增加一个用户含:Home 目录、客户shell,、注释 、UID/GID

    用‘-u‘ 定义UID (例. 1000) 和 用 ‘-g‘定义GID (例. 1000).

    [root@tecmint ~]# useradd -m -d /var/www/tarunika -s /bin/zsh -c "TecMint Technical Write
    r" -u 1000 -g 1000 tarunika

    13. 增加一个 用户含 :Home 目录、没有Shell、注释 、 UID

    用户 ‘avishek‘ 不能登陆到系统shell,而是/usr/sbin/nologin

    [root@tecmint ~]# useradd -m -d /var/www/avishek -s /usr/sbin/nologin -c "TecMint Sr. Tec
    hnical Writer" -u 1019 avishek

    14. 增加一个用户含:Home 目录,、Shell,、架构目录、注释、UID

     ‘-k‘ 选项设置客户架构/usr/sbin/nologin 目录、此例为: /etc//usr/sbin/nologin, 缺省为: /etc/skel.

      ‘-s‘ 选项定义不同的 shell。例:/bin/tcsh t到用户 ‘navin‘.

    [root@tecmint ~]# useradd -m -d /var/www/navin -k /etc/custom.skell -s /bin/tcsh -c "No A
    ctive Member of TecMint" -u 1027 navin

    15. 增加一个用户含:没有 Home目录、Shell,、组 、注释 

     使用  -M  没有 home 目录、-N‘ 仅创建一个用户名(没有组)、‘-r‘ 建立系统用户

    [root@tecmint ~]# useradd -M -N -r -s /bin/false -c "Disabled TecMint Member" clayton

    转载:http://risingair.blog.51cto.com/8381945/1861235
  • 相关阅读:
    31天重构学习笔记9. 提取接口
    31天重构学习笔记4. 降低方法
    31天重构学习笔记8. 使用委派代替继承
    31天重构学习笔记11. 使用策略类
    31天重构学习笔记12. 分解依赖
    MyCat:第八章:MyCAT In Action中文版
    HDU 2041 超级楼梯
    CSU 1487 未覆盖顶点数量
    HDU 1712 ACboy needs your help
    HDU 2034 人见人爱AB
  • 原文地址:https://www.cnblogs.com/huaerr/p/7832495.html
Copyright © 2020-2023  润新知