linux basic operation user 2

The basic operation of the system 2 user linux

3) Use userdeldelete account

语法 : userdel [-r] username   
        -r 同时删除家目录
        
 #删除用户目录
[root@centos7 ~]# userdel  user1
[root@centos7 ~]# ll /home/user1/ -d
drwx------. 2 1005 1009 62 Jun  5 04:22 /home/user1/

-r 连同家目录一起删除
[root@centos ~]# userdel -r user1

To understanding

1) Use the fingercommand to query information and login information
#如果没有则需要安装
[root@centos7 ~]# yum install -y finger
#使用方法
[root@centos7 ~]# finger zls
Login: zls                      Name:
Directory: /home/zls                    Shell: /bin/bash
Never logged in.
No mail.
No Plan.
2) Use the chfncommand to modify the user information
#修改用户信息
[root@centos7 ~]# chfn zls
Changing finger information for zls.
Name []: gjy
Office []: 老男孩教育
Office Phone []: 
Home Phone []:

Finger information changed.

#再次查看
[root@centos ~]# finger zls
Login: zls                      Name: gjy
Directory: /home/zls          Shell: /bin/bash
Office: 
Never logged in.
No mail.
No Plan.

3) Use the chshcommand to modify user login bash shell

[root@centos7 ~]# chsh zls
Changing shell for zls.
New shell [/bin/bash]: /sbin/nologin
Shell changed.

4) Use the who, whoami, wcheck user logins

[root@centos7 ~]# who
root     tty1         2019-06-20 17:48
root     pts/0        2019-06-27 08:27 (10.0.0.1)
root     pts/1        2019-06-27 14:16 (10.0.0.1)
root     pts/2        2019-06-27 14:11 (10.0.0.1)
[root@centos7 ~]# whoami
root
[root@centos7 ~]# w
 14:22:12 up 2 days, 23:04,  4 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1                      20Jun19  6days  0.03s  0.03s -bash
root     pts/0    10.0.0.1         08:27   11:16   0.17s  0.17s -bash
root     pts/1    10.0.0.1         14:16    4.00s  0.03s  0.01s w
root     pts/2    10.0.0.1         14:11   10:52   0.01s  0.01s -bash

Knowledge of the user's extension

The user creation process

  • When useradd to create the user, the system will /etc/login.defs, /etc/defaults/useraddtwo configuration files as a reference, if the parameter is specified when creating the user will be overwritten /etc/login.defs, /etc/defaults/useraddthe default configuration file, if not specified, the default
#查看配置文件
[root@centos7 ~]# less /etc/login.defs
#过滤空行,注释(如何实现)

#参数讲解
#用户的邮件目录
MAIL_DIR    /var/spool/mail
#密码最大天数
PASS_MAX_DAYS   99999
#密码最小天数
PASS_MIN_DAYS   0
#密码最小长度
PASS_MIN_LEN    5
#密码警告天数
PASS_WARN_AGE   7
#普通用户最小uid
UID_MIN                  1000
#普通用户最大uid
UID_MAX                 60000
#系统用户最小uid
SYS_UID_MIN               201
#系统用户最大uid
SYS_UID_MAX               999
#普通用户组最小gid
GID_MIN                  1000
#普通用户组最大gid
GID_MAX                 60000
#系统组最小gid
SYS_GID_MIN               201
#系统组最大gid
SYS_GID_MAX               999
#是否创建家目录
CREATE_HOME                 yes
#权限
UMASK           077
#删除用户时,是否要移除用户组
USERGROUPS_ENAB yes
#密码加密算法
ENCRYPT_METHOD SHA512

#查看useradd配置文件
[root@zls ~]# cat /etc/default/useradd
GROUP=100                 //依赖于/etc/login.defs的USE RGRUUPS_ENAB参数,如果为no,则在此处控制
HOME=/home                      //把用户的家目录建在/home中。
INACTIVE=-1                     //是否启用账号过期停权,-1表示不启用。
EXPIRE=                         //账号终止日期,不设置表示不启用。
SHELL=/bin/bash            //新用户默认所有的shell类型。
SKEL=/etc/skel                  //配置新用户家目录的默认文件存放路径。
CREATE_MAIL_SPOOL=yes       //创建mail文件。
  • When useraddcreating a user, there will be .bash_ * environment variables related files in the user's home directory is created, these environment variables default file copy in / etc / skel directory. This default copy environment variable position is defined by the / etc / defaults / useradd profile

    Enterprise Failure Case

#在当前用户的家目录下,想要删除所有文件,执行了如下命令
[root@db04 ~]# rm -fr .*
#结果再次登录时
-bash-4.1#

#解决办法
-bash-4.1# cp /etc/skel/.bash* .
#再次登录 即可恢复
[root@db04 ~]#

User Password Management

After creating an account, the default password is not set, so the account is no way to landing operating system. Use only passwdset up after the password to log into the system.

Use passwdwhen creating passwords for users, for security reasons, please try to set up complicated. Passwords can be set in accordance with the following rules:

1.密码的长度最好大于10位字符
2.密码中包含大小写字母数字以及特殊字符 ! @ # $
3.不规则性(不要出现自己名字、公司名字、自己电话、等等简单的密码)

requires attention:

1.普通用户只能更改自己的密码(密码必须满足8位字符)
2.管理员用户能更改任何人的密码(密码长度无限制)
1. Use the passwdcommand to modify user password
语法: passwd [username]

#'passwd'后面不加[username]则是修改当前登陆终端用户的密码。
#如果你登陆的是root管理员用户,后面可以指定要修改的用户。
#只有root管理员才可以修该其他用户的密码,普通账户只能修改自己的密码,并且普通用户没有修改其他用户密码的权限


#root管理员用户登陆,修改root用户密码
[root@centos7 ~]# passwd  
更改用户 root 的密码。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

#root用户登陆,修改其他用户的密码
[root@centos7 ~]# passwd zls
更改用户 zls 的密码
新的 密码:
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。


#普通用户修改root管理员密码
[zls@zls ~]$ passwd root
passwd: Only root can specify a user name.


#无需用户交互修改密码, 将前者的输出结果, 成为后者的输入
[root@zls ~]# echo "123" | passwd --stdin zls
Changing password for user zls.
passwd: all authentication tokens updated successfully.
2. random password generation complex way
#1.系统内置变量生成随机密码
[root@centos ~]# echo $RANDOM|md5sum|cut -c 1-10
693c116738
[root@zls ~]# echo $(echo $RANDOM|md5sum |cut -c 5-14) |tee pass.txt| passwd --stdin zls

示例:
[root@centos7 ~]# echo $RANDOM |md5sum |cut -c 1-10
9716177989
[root@centos7 ~]# echo $(echo $RANDOM|md5sum |cut -c 5-15) |tee test.txt |passwd --stdin liqi|bash
Changing password for user liqi.
passwd: all authentication tokens updated successfully.
[root@centos7 ~]# cat test.txt
c03cfa985c1
#2.mkpasswd密码生成工具,
-l设定密码长度,
-d数字,
-c小写字母,
-C大写字母,
-s特殊字符
[root@centos7 ~]# yum install -y expect   //需要安装扩展包
[root@centos7 ~]# mkpasswd -l 10 -d 2 -c 2 -C 2 -s 4
|K&13bR)i/
#创建10个qiudao开头的,并随机生成24位复杂密码
[root@centos7 ~]# seq '10'|awk '{print "useradd qiudao"$1";""mkpasswd -l 24 -d 2 -c 2 -C 3 -s 3| tee /tmp/old0"$1"|passwd --stdin qiudao"$1}'|bash

#创建10个qiudao开头的,并随机生成24位密码
[root@centos7 ~]# seq '10'|awk '{print "useradd qiudao"$1";""echo $RANDOM|md5sum|cut -c 1-24 | tee /tmp/old0"$1"|passwd --stdin oldboy"$1}'|bash
3. Recommended password hold client tools, support windows、MacOS、Iphone, and browser plug-ins

[Lastpass official website

Guess you like

Origin www.cnblogs.com/gongjingyun123--/p/11099363.html