zoukankan      html  css  js  c++  java
  • 【linux 用户和组管理】3-用户和组管理

    https://edu.aliyun.com/lesson_1717_14283#_14283

    cat /etc/default/useradd
    useradd -D

    useradd -D -s /bin/csh 修改
    useradd -D -s /bin/bash

    gourpadd webs

    newusers passwd格式文件 批量建用户
    newusers userlist.txt
    chpasswd
    user1:centos
    echo user1:centos | chpasswd
    cat > p.txt
    user1:centos
    cat p.txt | chpasswd

    • 用户属性修改
      usermod 改属性
      id mage
      usermod -G bin,wang mage 加附加组
      usermod -aG bin,wang mage 追加附加组
      usermod -G "" mage 清空附加组

    • 删除用户
      userdel li 删不干净
      userdel -r li 同时删除用户的其他数据

    • 查看用户相关的ID信息
      id wang
      id -g wang
      id -G test2
      id -Gn test2

    • 切换用户或以其他用户身份执行命令
      su UserName 非登录式切换,不读用户的配置文件,不改变工作目录,非完全切换
      su - UserName 登录式切换,读配置文件,切换家目录,完全切换
      su - 默认切换到root
      vim /etc/profile.d/test.sh 全局环境变量

    su - wang
    su - root -c 'cat /etc/shadow'
    logout

    • 设置密码
      passwd
      passwd -e mage 强制下次登录改口令

    echo $HISTCONTROL
    HISTCONTROL=ignoreboth
    echo mageedu | passwd --stdin wang 加空格,历史就没有了
    history

    • 修改用户密码策略
      chage

    • 用户相关的其他命令
      chfn 指定个人信息
      chsh 指定shell
      finger 查看

    • 创建组
      groupadd
      -g GID
      -r 创建系统组 centos7 ID<1000
      groupadd g1 -g 2000
      getent group g1

    • 修改和删除组
      groupmod -g 3000 -n newg1 g1
      getent group newg1

    groupdel newg1
    getent group newg1

    • 更改组密码
      gpasswd
      groupadd sales
      id mage
      gpasswd -a mage sales 加附加组
      gpasswd -d mage sales 删附加组
      newgrp 临时切换主组

    • 更改和查看组成员
      groupmems

    • 文件权限

  • 相关阅读:
    面试笔记之手写单例模式
    Java学习笔记六:Java最基础
    Mac下终端工具iTerm2的快捷键
    Typescript引用类型--字符串
    Typescript引用类型--数组
    Typescript函数作用域
    Typescript的函数定义方式
    初识Typescript以及Typescript的安装
    VS Code前端开发常用插件和常用快捷键
    Vue CLI3项目构建
  • 原文地址:https://www.cnblogs.com/sec875/p/13425635.html
Copyright © 2011-2022 走看看