用户管理
-
useradd
新增用户[root@localhost ~]# useradd john [root@localhost ~]# useradd -u 555 user1 # 指定UID [root@localhost ~]# useradd -g user1 user2 # 指定GID [root@localhost ~]# useradd -d /home/mydir3 user3 #指定home目录
-
passwd
设置密码root用户
bash [root@localhost ~]# passwd john Changing password for user john. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully. [root@localhost ~]#
> 普通用户
bash [john@localhost ~]$ passwd Changing password for user john. Changing password for john. (current) UNIX password: New password: Retype new password: passwd: all authentication tokens updated successfully. [john@localhost ~]$
-
usermod
修改用户[root@localhost ~]# useradd alice [root@localhost ~]# passwd alice Changing password for user alice. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully. [root@localhost ~]# cat /etc/passwd | grep alice alice:x:1002:1002::/home/alice:/bin/bash # 修改用户alice home目录 [root@localhost ~]# usermod -d /home/alice_new -m alice [root@localhost ~]# cat /etc/passwd | grep alice alice:x:1002:1002::/home/alice_new:/bin/bash
-
userdel
删除用户[root@localhost ~]# userdel alice [root@localhost ~]#
-
groupadd
新增用户组[root@localhost home]# groupadd group1 [root@localhost home]#
-
groupdel
删除用户组[root@localhost home]# groupdel group1
-
users who w
查看用户[root@localhost home]# users root test [root@localhost home]# who root pts/0 2019-01-08 01:57 (192.168.56.1) test pts/1 2019-01-08 01:16 (192.168.56.1) [root@localhost home]# w 02:24:09 up 4:24, 2 users, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.56.1 01:57 1.00s 0.09s 0.01s w test pts/1 192.168.56.1 01:16 30:09 0.03s 0.03s -bash
w
命令
* 第一行显示 当前时间 系统运行时间 已登录用户数 系统负载
* 下面信息分为8列:
+ 登录用户的用户名
+ 用户登录终端
+ 如果用户从网络登录,显示远程主机的主机名或IP
+ 用户登录时间
+ 用户闲置时间
+ 与终端相关的当前所有运行进程消耗的CPU时间总量
+ 当前WHAT列所对应的进程消耗的CPU时间总量
+ 用户当前运行的进程 -
finger
调查用户[root@localhost ~]# finger Login Name Tty Idle Login Time Office Office Phone Host root root pts/1 Jan 8 04:14 (192.168.56.1) test pts/0 24 Jan 8 04:14 (192.168.56.1) [root@localhost ~]# finger test Login: test Name: Directory: /home/test Shell: /bin/bash On since Tue Jan 8 04:14 (EST) on pts/0 from 192.168.56.1 25 minutes 18 seconds idle No mail. No Plan. [root@localhost ~]#
-
su
切换用户切换用户
bash [test@localhost ~]$ su Password: [root@localhost test]# pwd /home/test [root@localhost test]# exit exit [test@localhost ~]$
> 切换用户环境
bash [test@localhost ~]$ su - Password: Last login: Tue Jan 8 04:22:09 EST 2019 on pts/0 [root@localhost ~]# pwd /root [root@localhost ~]# exit logout [test@localhost ~]$
-
sudo
用其他用户身份执行命令[root@localhost ~]# visudo [john@localhost test]$ sudo passwd user1 We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. [sudo] password for john: Changing password for user user1. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully.
-
at
单一时刻执行一次任务at
atq
atrm
cron
周期性执行任务