Linux删除、修改、添加、切换用户及修改密码


默认用户:root 管理员用户
  默认组:root
Linux默认自带的用户的id都在500以内,用户自己创建的用户id从500开始
用户配置文件:/etc/passwd
root:x:0:0:root:/root:/bin/bash
用户名:密码:用户id:组id:组名称:家目录:使用的shell类型

管理组

查看所有组cat /etc/group

查看当前登录用户所在的组groups

查看用户test所在组groups test

增加一个test组groupadd hadoop

将hadoop组的名子改成hivegroupmod -n hive hadoop

删除组hivegroupdel hive

管理用户

[fuyun@bigdata-training hive-3.1.1]$ sudo useradd -help
useradd: invalid option -- 'h'
Usage: useradd [options] LOGIN

Options:
  -b, --base-dir BASE_DIR       base directory for the home directory of the
                                new account  #新账户的主目录的基目录
  -c, --comment COMMENT         GECOS field of the new account  #新账户的GECOS字段
  -d, --home-dir HOME_DIR       home directory of the new account  #新账户的家目录
  -D, --defaults                print or change default useradd configuration  #显示或变更
  -e, --expiredate EXPIRE_DATE  expiration date of the new account  #新账户的过期日期
  -f, --inactive INACTIVE       password inactivity period of the new account  #新账户的密码不活动期
  -g, --gid GROUP               name or ID of the primary group of the new
                                account  #新账户的主组或ID
  -G, --groups GROUPS           list of supplementary groups of the new
                                account  #新账户的附加主列表
  -h, --help                    display this help message and exit  #显示此帮助信息并退出
  -k, --skel SKEL_DIR           use this alternative skeleton directory  #使用此目录作为骨架目录
  -K, --key KEY=VALUE           override /etc/login.defs defaults  #不使用/etc/login.defs的默认值
  -l, --no-log-init             do not add the user to the lastlog and
                                faillog databases  #不要将此目录添加到最近登录或登录失败的数据库
  -m, --create-home             create the user's home directory  #创建用户的主目录
  -M, --no-create-home          do not create the user's home directory  #不创建用户的主目录
  -N, --no-user-group           do not create a group with the same name as
                                the user  #不创建同名的组
  -o, --non-unique              allow to create users with duplicate
                                (non-unique) UID  #允许使用重复的UID创建用户
  -p, --password PASSWORD       encrypted password of the new account  #加密后的新账户密码
  -r, --system                  create a system account  #创建一个系统用户
  -s, --shell SHELL             login shell of the new account  #新账户的登录shell
  -u, --uid UID                 user ID of the new account  #新账户的用户ID
  -U, --user-group              create a group with the same name as the user  #创建与用户同名的组
  -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping  #为SELinux用户映射使用指定的SEUSER
[fuyun@bigdata-training hive-3.1.1]$ sudo usermod -h
Usage: usermod [options] LOGIN

Options:
  -c, --comment COMMENT         new value of the GECOS field  #GECOS字段的新值
  -d, --home HOME_DIR           new home directory for the user account  #账户的新主目录
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE  #设定账户过期的日期为EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE  #过期INACTIVE天数后,设定密码为失效状态
  -g, --gid GROUP               force use GROUP as new primary group  #强制使用GROUP为新的主目录
  -G, --groups GROUPS           new list of supplementary GROUPS  #新的附加组列表GROUPS
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups  #将用户追加到上边-G中提到的附加组中,并不从其他组中删除此用户
  -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)  #将主目录移至新位置(仅与-d一起使用)
  -o, --non-unique              allow using duplicate (non-unique) UID  #允许使用重复的(非唯一的)UID
  -p, --password PASSWORD       use encrypted password for the new password  #将加密过的密码(PASSWORD)设为新密码
  -s, --shell SHELL             new login shell for the user account  #新用户账号的新登陆shell
  -u, --uid UID                 new UID for the user account  #用户账号的新UID
  -U, --unlock                  unlock the user account  #解锁用户账号
  -Z, --selinux-user            new SELinux user mapping for the user account  #用户账号的新SELinux用户映射

添加用户

useradd -g hive -m  hive                       #添加hive到hive组并创建用户目录(要先创建hive组)
useradd -g test -M -s /sbin/nologin  qtest      #添加qtest到test组不创建用户目录,并且不可用于登录

修改hive用户密码

passwd hive

id hive                                 #查看hive用户的UID和GID
usermod -d /home/hive1 -G hive hive     #将hive用户的登录目录改
usermod -s /bin/bash qtest               #修改qtest用户可登录
gpasswd -a hive test3    #将用户hive加入到test3组(用户可以属于多个组)
gpasswd -d hive test3     #将用户hive从test3组中移出

查看所有用户

cat /etc/passwd             #查看所有用户的列表
w                           #查看当前活跃的用户列表
pkill -kill -t pts/1        #踢掉活跃用户(最后一个参数为需要踢掉用户的tty参数)

w
 05:03:47 up  4:09,  5 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1     -                00:54    4:09m  0.00s  0.00s -bash
fuyun    pts/0    192.200.129.1    01:01    3:13   0.08s  0.08s -bash
fuyun    pts/1    192.200.129.1    05:01   33.00s  0.03s  0.02s ssh hive@192.200.129.66
hive     pts/2    bigdata-training 05:01   33.00s  0.01s  0.01s -bash
fuyun    pts/3    192.168.235.1    05:03    0.00s  0.02s  0.04s sshd: fuyun [priv]

查看登录日志

more /var/log/secure
who /var/log/wtmp 

who命令是显示目前登录系统的用户信息。
执行who命令可得知目前有那些用户登入系统,单独执行who命令会列出登入帐号,使用的终端机,登入时间以及从何处登入或正在使用哪个X显示器

who -a
           system boot  2019-07-02 00:54
           run-level 3  2019-07-02 00:54
root     + tty1         2019-07-02 00:54 04:35        2041
LOGIN      tty2         2019-07-02 00:54              2043 id=2
LOGIN      tty3         2019-07-02 00:54              2045 id=3
LOGIN      tty4         2019-07-02 00:54              2048 id=4
LOGIN      tty5         2019-07-02 00:54              2050 id=5
LOGIN      tty6         2019-07-02 00:54              2052 id=6
fuyun    + pts/0        2019-07-02 01:01 00:29        2918 (192.200.129.1)
           pts/1        2019-07-02 05:04              2918 id=ts/1  term=0 exit=0
           pts/2        2019-07-02 05:04              4497 id=ts/2  term=0 exit=0
fuyun    + pts/3        2019-07-02 05:03   .          2918 (192.200.129.1)


who -q  #只显示登入系统的帐号名称和总人数
root fuyun fuyun
# users=3

查看用户操作记录(使用root账号)

su - hive    #切换到要查看的目录
history     #能看到这个用户历史命令,默认最近的1000条

创建管理员权限的账号

useradd -o -u 0 -g 0 -M -d /root -s /bin/bash admin    #拥有root 一样的权限
passwd admin
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值