• linux 新建用户和权限分配


    1.创建新用户:testuser

    命令:#useradd 选项 用户名

    选项:

    -c comment 指定一段注释性描述。

    -d 目录 指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录。

    -g 用户组 指定用户所属的用户组。

    -G 用户组,用户组 指定用户所属的附加组。

    -s Shell文件 指定用户的登录Shell。

    -u 用户号 指定用户的用户号,如果同时有-o选项,则可以重复使用其他用户的标识号。

    示例:

      [root@localhost /]#  useradd testuser 

    2.删除testuser用户

    命令:#userdel 选项 用户名

    选项:

      -r 它的作用是把用户的主目录一起删除。

    示例:

    [root@localhost /]#  userdel  testuser 

    [root@localhost /]#  cd /home

    [root@localhost /]#  rm -rf testuser

    3.修改用户

    命令:#usermod 选项 用户名

    选项:

     -c, --comment COMMENT         new value of the GECOS field

      -d, --home HOME_DIR           new home directory for the user account

      -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE

      -f, --inactive INACTIVE       set password inactive after expiration  to INACTIVE

      -g, --gid GROUP               force use GROUP as new primary group

      -G, --groups GROUPS           new list of supplementary GROUPS

      -a, --append                  append the user to the supplemental GROUPS   mentioned by the -G option without removing  him/her from other groups

      -h, --help                    display this help message and exit

      -l, --login NEW_LOGIN         new value of the login name

      -L, --lock                    lock the user account

      -m, --move-home               move contents of the home directory to the   new location (use only with -d)

      -o, --non-unique              allow using duplicate (non-unique) UID

      -p, --password PASSWORD       use encrypted password for the new password

      -s, --shell SHELL             new login shell for the user account

      -u, --uid UID                 new UID for the user account

      -U, --unlock                  unlock the user account

      -Z, --selinux-user            new SELinux user mapping for the user account

    示例:

          //用户组改为developer。

      # usermod  –g developer sam

    4.用户口令(密码)管理:

    用户管理的一项重要内容是用户口令的管理。用户账号刚创建时没有口令,但是被系统锁定,无法使用,必须为其指定口令后才可以使用,即使是指定空口令。

    命令:#passwd 选项 用户名

    选项:

    -l 锁定口令,即禁用账号。

    -u 口令解锁。

    -d 使账号无口令。

    -f 强迫用户下次登录时修改口令。

    示例:

    [root@localhost /]#  passwd sam

    New password:*******

    Re-enter new password:*******

    5.添加组:

    命令:#groupadd 选项 用户组

    选项:

    -g GID 指定新用户组的组标识号(GID)。

    -o 一般与-g选项同时使用,表示新用户组的GID可以与系统已有用户组的GID相同。

    示例:

      [root@localhost /]#  groupadd group1

    6.删除组:

    命令:#groupdel 用户组

    选项:

    示例:

      [root@localhost /]#  groupdel group1

    7.删除组:

    命令:#groupmod 选项 用户组

    选项:

    -g GID 为用户组指定新的组标识号。

    -o 与-g选项同时使用,用户组的新GID可以与系统已有用户组的GID相同。

    -n新用户组 将用户组的名字改为新名字

    示例:

    //此命令将组group2的标识号改为10000,组名修改为group3。

      [root@localhost /]# groupmod –g 10000 -n group3 group2

    8. 新建用户的独立性 

    修改目录权限,使得Linux 每个账户只能查看自己的根目录,无法查看其它账户的目录。 首先要进入Linux系统下所有用户所在的文件夹

      [root@localhost /]# cd /home/testuser 

    //这就是说设置testuser 这个目录只有lili可以查看,Linux下的其它账户无法查看。

      [root@localhost /]#  chmod go-rw  testuser 

     

    9.其他命令:

    [root@localhost /]# cat /etc/passwd 可以查看用户的pass

    [root@localhost /]# cat /etc/shadow 可以查看用户名

    [root@localhost /]# cat /etc/group  可以查看 组

  • 相关阅读:
    liunx下一些服务小知识
    hausaufgabe--python 32
    hausaufgabe--python 31
    UnicodeDecodeError: 'gbk' codec can't decode byte 0xbc in position 21: illegal multibyte sequence
    hausaufgabe--python 30
    Running error: 'utf-8' codec can't decode byte 0xb4 in position 0: invalid start byte
    hausaufgabe--python 29- File 2
    Hausaufgabe--Python 28-- File 1
    hausaufgabe--python 27
    hausaufgabe--python 26 -Dict 2
  • 原文地址:https://www.cnblogs.com/yysbolg/p/8566622.html
Copyright © 2020-2023  润新知