zoukankan      html  css  js  c++  java
  • Linux 系统管理 04—账号管理

    1.添加用户账号 useradd命令示例:

    [root@localhost ~]# groupadd group1

    [root@localhost ~]# mkdir -p /testgroup1

    [root@localhost ~]# groupadd DMXY

    [root@localhost ~]# useradd -d /testgroup1/DMXY/ -g group1 -G DMXY -s /bin/basha -e 2019-01-01 DMXY

    [root@localhost ~]# passwd DMXY

    [root@localhost ~]# tail -1 /etc/passwd

    DMXY:x:1001:1001::/testgroup1/DMXY/:/bin/basha

    [root@localhost ~]# tail -1 /etc/shadow

    DMXY:$6$w.kj4AHS$/VMddBNPl2Rv/4Nb3.JWRrTz3OqdM5MrKGOEX4bwIgRDqFmKXDZx9vc5N5teqJKr26J9AcHEZJjOGa8OF79cK.:18106:0:99999:7::17897:

    2.用户账号的初始配置文件

    [root@localhost ~]# vi ~DMXY/.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"demaxiyawansui"

    ~                                                                                                               

    ~                                                                                                                                                                                            

                                                                                                     

    ~                                                                                                                

    "/testgroup1/DMXY//.bash_profile" 13L, 214C

    [root@localhost ~]# vi ~DMXY/.bashrc

    # .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"suiyuanbizhu"

    ~                                                                                                               

    ~                                                                                                                

    ~                                                                                                               

                                                                                                     "/testgroup1/DMXY//.bashrc" 12L, 250C

    3.设置/修改用户口令 passwd命令示例:

    [root@localhost ~]# passwd -l DMXY

    锁定用户 DMXY 的密码 。

    passwd: 操作成功

    [root@localhost ~]# passwd -S DMXY

    DMXY LK 2019-07-29 0 99999 7 -1 (密码已被锁定。)

    [root@localhost ~]# passwd -u DMXY

    解锁用户 DMXY 的密码。

    passwd: 操作成功

    [root@localhost ~]# passwd -d DMXY

    清除用户的密码 DMXY。

    passwd: 操作成功

    [root@localhost ~]# passwd DMXY

    passwd:所有的身份验证令牌已经成功更新

    [root@localhost ~]# passwd -x 120 DMXY

    调整用户密码老化数据DMXY。

    passwd: 操作成功

    [root@localhost ~]# grep DMXY /etc/shadow

    DMXY:$6$jKrU1fFX$ycWTUJi9VOW0ZwALgXGBF.K11DNw0pSH6mQ/NGBCLWReo.Hl6RGu2WNs7Z1A05so64l2EwUzpj/Ki856n8KpO.:18106:0:120:7::17897:

    [root@localhost ~]# passwd -n 1 DMXY

    调整用户密码老化数据DMXY。

    passwd: 操作成功

    [root@localhost ~]# grep DMXY /etc/shadow

    DMXY:$6$jKrU1fFX$ycWTUJi9VOW0ZwALgXGBF.K11DNw0pSH6mQ/NGBCLWReo.Hl6RGu2WNs7Z1A05so64l2EwUzpj/Ki856n8KpO.:18106:1:120:7::17897:

    [root@localhost ~]# passwd -w 5 DMXY

    调整用户密码老化数据DMXY。

    passwd: 操作成功

    [root@localhost ~]# grep DMXY /etc/shadow

    DMXY:$6$jKrU1fFX$ycWTUJi9VOW0ZwALgXGBF.K11DNw0pSH6mQ/NGBCLWReo.Hl6RGu2WNs7Z1A05so64l2EwUzpj/Ki856n8KpO.:18106:1:120:5::17897:

    [root@localhost ~]# passwd -i 7 DMXY

    调整用户密码老化数据DMXY。

    passwd: 操作成功

    [root@localhost ~]# grep DMXY /etc/shadow

    DMXY:$6$jKrU1fFX$ycWTUJi9VOW0ZwALgXGBF.K11DNw0pSH6mQ/NGBCLWReo.Hl6RGu2WNs7Z1A05so64l2EwUzpj/Ki856n8KpO.:18106:1:120:5:7:17897:

    4.修改用户属性 usermod命令示例:

    [root@localhost ~]# usermod -l DMXY1 DMXY

    [root@localhost ~]# tail -1 /etc/passwd

    DMXY1:x:1001:1001::/testgroup1/DMXY/:/bin/basha

    [root@localhost ~]# usermod -c DMXY DMXY1

    [root@localhost ~]# tail -1 /etc/passwd

    DMXY1:x:1001:1001:DMXY:/testgroup1/DMXY/:/bin/basha

    删除用户账号userdel命令

    [root@localhost ~]# userdel -r DMXY1

    [root@localhost ~]# ls /testgroup1/

    5.添加组账号groupadd命令示例:

    [root@localhost ~]# tail -3 /etc/group

    zxs:x:1000:

    group1:x:1001:

    DMXY:x:1002:

    [root@localhost ~]# groupadd -g 888 maket

    [root@localhost ~]# tail -4 /etc/group

    zxs:x:1000:

    group1:x:1001:

    DMXY:x:1002:

    maket:x:888:

    6.设置组账号密码,添加、删除成员gpasswd命令示例:

    [root@localhost ~]# useradd xs1

    [root@localhost ~]# useradd xs2

    [root@localhost ~]# useradd xs3

    [root@localhost ~]# gpasswd -a xs1 maret

    正在将用户“xs1”加入到“maket”组中

    [root@localhost ~]# tail -4 /etc/group

    test3:x:1005:

    xs1:x:1006:

    xs2:x:1007:

    xs3:x:1008:

    [root@localhost ~]# gpasswd -d xs1 maket

    正在将用户“xs1”从“maket”组中删除

    [root@localhost ~]# tail -4 /etc/group

    test3:x:1005:

    xs1:x:1006:

    xs2:x:1007:

    xs3:x:1008:

    [root@localhost ~]# gpasswd -M xs1,xs2,xs3 maket

    [root@localhost ~]# tail -4 /etc/group

    test3:x:1005:

    xs1:x:1006:

    xs2:x:1007:

    xs3:x:1008:

    [root@localhost ~]# tail -3 /etc/group

    xs1:x:1006:

    xs2:x:1007:

    xs3:x:1008:

    7.删除组账号groupdel命令示例:

    [root@localhost ~]# groupdel maket

    [root@localhost ~]# tail -5 /etc/group

    test2:x:1004:

    test3:x:1005:

    xs1:x:1006:

    xs2:x:1007:

    xs3:x:1008:

    8.查询命令-------ID、groups、finger、w、whoami、who

    id命令:

    [root@localhost ~]# id xs1

    uid=1004(xs1) gid=1006(xs1) 组=1006(xs1)

    [root@localhost ~]# id

    uid=0(root) gid=0(root) 组=0(root) 环境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

    groups命令:

    [root@localhost ~]# groups xs1

    xs1 : xs1

    [root@localhost ~]# groups

    root

    finger命令:

    [root@localhost ~]# finger xs1

    Login: xs1                            Name:

    Directory: /home/xs1                      Shell: /bin/bash

    Never logged in.

    No mail.

    No Plan.

    [root@localhost ~]# finger

    Login     Name       Tty      Idle  Login Time   Office     Office Phone   Host

    root      root      *:0             Jul 23 19:38                           (:0)

    root      root       pts/0          Jul 29 09:15                           (192.168.100.106)

    w命令:

    [root@localhost ~]# w

     14:44:04 up  5:33,  2 users,  load average: 0.16, 0.05, 0.06

    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

    root     :0       :0               二19   ?xdm?   2:08   0.21s /usr/libexec/gnome-session-binary --session gnom

    root     pts/0    192.168.100.106  09:15    4.00s  0.62s  0.06s w

    whoami命令:

    [root@localhost ~]# whoami

    root

    who命令:

    [root@localhost ~]# who

    root     :0           2019-07-23 19:38 (:0)

    root     pts/0        2019-07-29 09:15 (192.168.100.106)

  • 相关阅读:
    SyntaxError: Non-ASCII character 'xe7' in file解决方法
    python实现微信打飞机游戏
    ubuntu 系统出错一览
    MVC的特点
    架构
    策略模式
    bin
    使用XSLT实现Word下载
    <a>标签的href属性
    call-template和apply-templates
  • 原文地址:https://www.cnblogs.com/wangjia120/p/11263950.html
Copyright © 2011-2022 走看看