• 用户管理及权限归属


    新建用户

      useradd 用户名 [-u 用户id] [-d 家目录] [-G 附加组] [-s 解释器] 

    [root@server0 ~]# useradd -u 1600 -d /root/harry -s /sbin/nologin -G root harry
    [root@server0 ~]# id harry uid=1600(harry) gid=1600(harry) 组=1600(harry),0(root)

     查看用户基本信息

      id 用户名

    [root@L ~]# id root
    uid=0(root) gid=0(root) 组=0(root)

    修改秘密:

      passwd 用户名

      echo '密码‘ | passwd --stdin 用户名          --非交互式的修改密码

    修改用户属性

      usermod [-u 用户id] [-d 家目录] [-G 附加组] [-s 解释器]

    删除用户

      userdel [-r] 用户名 ----------[可选择删除家目录]  删除用户 

    添加组:   /etc/group   /erc/gshadow

      groupadd [-g 组id] 组名

    [root@server0 ~]# groupadd stu_grp

    管理组成员:

      gpasswd -a 用户名 组名           -----添加成员

      gpasswd -d 用户名 组名      -----删除成员  

    [root@server0 ~]# gpasswd -a harry stu_grp
    正在将用户“harry”加入到“stu_grp”组中

    修改组属性

      groupmod [-g 组id] [-n 新组名] 组名

    删除组

      groupdel 组名

      

    查看权限: 

        ls -l  目录     查看文本文件权限

        ls -ld 文件    查看目录文件权限

    [root@server0 ~]# mkdir -p /test/test01
    [root@server0 ~]# ls -ld /test/test01
    drwxr-xr-x. 2 root root 6 11月  6 20:39 /test/test01
    [root@server0 ~]# touch /test/test01.txt
    [root@server0 ~]# ls -l /test/test01.txt
    -rw-r--r--. 1 root root 0 11月  6 20:40 /test/test01.txt
    [root@server0 ~]# 

    修改权限:

      chmod o+x file_path          给其他用户添加执行权限

      chmod o-x file_path        除去其他用户的执行权限

      chmod u+x,g-w,o-w  file_path        给所有者添加执行权限,所属组除去写权限,其他用户除去写权限 

      chmod u=rwx,g=rx,o=rx                 所有者读写执行权限,所属组和其他用户都执行权限

        chmod ugo=rwx         所有人读写执行权限 

      chmod 777           所有人读写执行权限

    [root@server0 ~]# ls -ld /test/
    drwxr-xr-x. 3 root root 36 11月  6 20:40 /test/
    [root@server0 ~]# chmod o+w /test/
    [root@server0 ~]# ls -ld /test/
    drwxr-xrwx. 3 root root 36 11月  6 20:40 /test/
    [root@server0 ~]# chmod u-w,g-x,o-w /test/
    [root@server0 ~]# ls -ld /test/
    dr-xr--r-x. 3 root root 36 11月  6 20:40 /test/
    [root@server0 ~]# chmod u=rwx,g=rw,o=r /test/
    [root@server0 ~]# ls -ld /test/
    drwxrw-r--. 3 root root 36 11月  6 20:40 /test/
    [root@server0 ~]# chmod ugo=--- /test/
    [root@server0 ~]# ls -ld /test/
    d---------. 3 root root 36 11月  6 20:40 /test/
    [root@server0 ~]# chmod 777 /test/
    [root@server0 ~]# ls -ld /test/
    drwxrwxrwx. 3 root root 36 11月  6 20:40 /test/
    [root@server0 ~]# 

    修改组

      chown 所有者:所属组  文件

      修改文件的所有者,所属组

    [root@S opt]# mkdir /opt/test
    [root@S opt]# ls -ld /opt/test/
    drwxr-xr-x. 2 root root 6 11月  7 09:08 /opt/test/
    [root@S opt]# chown harry:harry /opt/test/
    [root@S opt]# ls -ld /opt/test/
    drwxr-xr-x. 2 harry harry 6 11月  7 09:08 /opt/test/
    [root@S opt]# 
  • 相关阅读:
    删库了一定要跑路吗?爱情 36 技之记忆重生!
    程序员和他的朋友们!
    聊起 BigTable,让你不再胆怯
    [Ant Design] Warning: Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?
    Git 常用命令
    Git 名词解释
    js中void 0和undefined的区别
    js运算符优先级
    搭建React项目(低配版)
    mac常用shell指令笔记
  • 原文地址:https://www.cnblogs.com/ray-mmss/p/9915495.html
Copyright © 2020-2023  润新知