• linux系统命令2


    [root@localhost ~]# groupadd group1       //创建组账号
    [root@localhost ~]# mkdir -p /testgroup1      //创建目录
    [root@localhost ~]# groupadd jiaoxue           //创建组账号
    [root@localhost ~]# useradd -d /testgroup1/tom/ -g group1 -G jiaoxue -s /bin/bash -e 2016-7-29 tom        //指定宿主目录   基本组名  附加组名  用户登录Shell和账号失效时间
    [root@localhost ~]# passwd tom            //设置用户密码
    更改用户 tom 的密码 。
    新的 密码:
    无效的密码: 密码未通过字典检查 - 过于简单化/系统化
    重新输入新的 密码:
    passwd:所有的身份验证令牌已经成功更新。

    [root@localhost ~]# tail -1 /etc/passwd         //查看用户名称 宿主目录 登录Shell等基本信息
    tom:x:1001:1001::/testgroup1/tom/:/bin/bash
    [root@localhost ~]# tail -1 /etc/shadow         //查看用户密码 账号等有效信息
    tom:$6$gyF7wJ9F$kCnolmtcBXgxfzvpIQwXpefCANc/AiSuvSYDw45a4Ra/7h30wseW2sUIV3ne6KspoxgLnoY.WHQ6Ed6pWolrO0:18106:0:99999:7::17011:

    [root@localhost ~]# vi ~tom/.bash_profile        //每次登录时执行

    # .bash_profile

    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi

    # User specific environment and startup programs

    PATH=$PATH:$HOME/.local/bin:$HOME/bin

    export PATH
    echo "welcome tom!"
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    :wq       //保存退出

    [root@localhost ~]# vi ~tom/.bashrc       //每次进入新的bash环境时执行

    # .bashrc

    # Source global definitions
    if [ -f /etc/bashrc ]; then
    . /etc/bashrc
    fi

    # Uncomment the following line if you don't like systemctl's auto-paging feature:
    # export SYSTEMD_PAGER=

    # User specific aliases and functions
    echo "hi!this is a new bash!"
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    :wq

    [root@localhost ~]# vi ~tom/.bash_logout         //退出登录时执行

    # ~/.bash_logout
    each "byebye tom!"
    sleep 3
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    :wq

    [root@localhost ~]# passwd -l tom       //锁定用户密码
    锁定用户 tom 的密码 。
    passwd: 操作成功
    [root@localhost ~]# passwd -S tom      //查看用户账号状态
    tom LK 2019-07-29 0 99999 7 -1 (密码已被锁定。)
    [root@localhost ~]# passwd -u tom      //解锁用户密码
    解锁用户 tom 的密码。
    passwd: 操作成功
    [root@localhost ~]# passwd -S tom          //查看用户账号状态
    tom PS 2019-07-29 0 99999 7 -1 (密码已设置,使用 SHA512 算法。)
    [root@localhost ~]# passwd -d tom        //清除用户密码
    清除用户的密码 tom。
    passwd: 操作成功

    [root@localhost ~]# usermod -l tom1 tom        //更改账户的登录名字

    [root@localhost ~]# tail -1 /etc/passwd             //查看用户名称 宿主目录 登录Shell等基本信息
    tom:x:1001:1001::/testgroup1/tom/:/bin/bash

    [root@localhost ~]# usermod -c jiaoxue tom              /// 修改用户备注

    [root@localhost ~]# tail -1 /etc/passwd         //查看用户名称 宿主目录 登录Shell等基本信息
    tom:x:1001:1001:jiaoxue:/testgroup1/tom/:/bin/bash

    [root@localhost ~]# userdel -r tom1             //同时删除用户的宿主目录

    [root@localhost ~]# useradd test1              //创建用户test1
    [root@localhost ~]# useradd test2              //创建用户test2
    [root@localhost ~]# useradd test3              //创建用户test3       

    [root@localhost ~]# groupadd market          //创建组账号

    [root@localhost ~]# gpasswd -a test1 market         // 向market添加test1
    正在将用户“test1”加入到“market”组中
    [root@localhost ~]# tail -4 /etc/group        //查看/etc/group中后四行的信息
    test1:x:1003:
    test2:x:1004:
    test3:x:1005:
    market:x:1006:test1

    [root@localhost ~]# gpasswd -d test1 market          //从market删除test1
    正在将用户“test1”从“market”组中删除
    [root@localhost ~]# tail -4 /etc/group                       //查看/etc/group中后四行的信息
    test1:x:1003:
    test2:x:1004:
    test3:x:1005:
    market:x:1006:

    [root@localhost ~]# gpasswd -M test1,test2,test3 market                      //定义组成员test1,test2,test3
    [root@localhost ~]# tail -4 /etc/group                                                      //查看/etc/group中后四行的信息 
    test1:x:1003: 
    test2:x:1004:
    test3:x:1005:
    market:x:1006:test1,test2,test3
    [root@localhost ~]# gpasswd -M test1 market                                      //定义组成员test1
    [root@localhost ~]# tail -4 /etc/group                                                    //查看/etc/group中后四行的信息
    test1:x:1003:
    test2:x:1004:
    test3:x:1005:
    market:x:1006:test1

    [root@localhost ~]# groupdel market                  //删除组账号
    [root@localhost ~]# tail -5 /etc/group                   //查看/etc/group中后五行的信息
    group1:x:1001:
    jiaoxue:x:1002:tom
    test1:x:1003:
    test2:x:1004:
    test3:x:1005:

    [root@localhost ~]# id  【用户名】                      //查询用户身份标识
    uid=0(root) gid=0(root) 组=0(root) 环境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
    [root@localhost ~]# groups  【用户名】              //查询客户所属的组
    root

    [root@localhost ~]# finger  【用户名】                 //查询账号的详细信息
    Login Name Tty Idle Login Time Office Office Phone Host
    root root *:0 Jul 29 14:23 (:0)
    root root pts/0 2:04 Jul 29 14:24 (:0)
    root root pts/1 Jul 29 14:26 (192.168.100.141)
    [root@localhost ~]# w                          //查询已登录到主机的用户信息

    16:28:52 up 2:06, 3 users, load average: 0.27, 0.08, 0.07
    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
    root :0 :0 14:23 ?xdm? 36.22s 0.09s gdm-session-worker [pam/gdm-password]
    root pts/0 :0 14:24 2:04m 0.01s 0.01s /bin/bash
    root pts/1 192.168.100.141 14:26 4.00s 0.24s 0.02s w
    [root@localhost ~]# whoami                //查询当前登录的账户名
    root
    [root@localhost ~]# who                       与w命令类似,查询已登录到主机的用户
    root :0 2019-07-29 14:23 (:0)
    root pts/0 2019-07-29 14:24 (:0)
    root pts/1 2019-07-29 14:26 (192.168.100.141)

  • 相关阅读:
    帮助理解Docker,生动装逼介绍Docker
    Java 最常见 200+ 面试题 + 全解析
    CentOS7.0 yum安装 docker
    集合总结
    C#复习笔记
    match方法的使用
    偏函数
    通用装饰器
    装饰器修饰带参数的功能函数
    多个装饰器的使用
  • 原文地址:https://www.cnblogs.com/mengwei123/p/11264710.html
Copyright © 2020-2023  润新知