Linux添加用户组和添加用户
1.用户组
- 添加组:groupadd 组名
[root@Server-n93yom ~]# groupadd dev
[root@Server-n93yom ~]# cat /etc/group | grep dev
dev:x:10011:
[root@Server-n93yom ~]# - 删除组:groupdel 组名
[root@Server-n93yom ~]# groupdel dev
[root@Server-n93yom ~]# cat /etc/group | grep dev
[root@Server-n93yom ~]# - 查询组:cat /etc/group 或者使用管道来精确查询 cat /etc/group | grep dev
[root@Server-n93yom ~]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:30:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
ssh_keys:x:999:
input:x:998:
systemd-journal:x:190:
systemd-bus-proxy:x:997:
systemd-network:x:192:
dbus:x:81:
polkitd:x:996:
tss:x:59:
dip:x:40:
postdrop:x:90:
postfix:x:89:
sshd:x:74:
check:x:1000:check
cfyuser:x:10000:
consul:x:10002:
rabbitmq:x:10003:
mysql:x:10009:
prometheus:x:10004:
grafana:x:10005:
logstash:x:10006:
nginx:x:995:
tomcat:x:10008:
guanbin:x:10010:
dev:x:10011:
/etc 目录是专门用来保存 系统配置信息 的目录
group 是保存组信息的文件
2.用户
- 添加用户:useradd -m -g 组 新建用户名 注意:-m 自动建立用户家目录; -g 指定用户所在的组,否则会建立一个和用户名同名的组
[root@Server-n93yom ~]# useradd -m -g dev test1
[root@Server-n93yom ~]#dev为用户组,test1为用户名
- 查询用户:在/etc/passwd文件下存储的是用户的list
[root@Server-n93yom ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
check:x:1000:1000:check:/home/check:/bin/bash
cfyuser:x:10000:10000::/home/cfyuser:/bin/bash
consul:x:10002:10002::/opt/cloudchef/consul:/sbin/nologin
rabbitmq:x:10003:10003::/etc/rabbitmq:/sbin/nologin
mysql:x:10009:10009::/home/mysql:/bin/bash
prometheus:x:10004:10004::/home/prometheus:/sbin/nologin
grafana:x:10005:10005::/home/grafana:/bin/bash
logstash:x:10006:10006::/home/logstash:/bin/bash
nginx:x:997:995:nginx user:/var/cache/nginx:/sbin/nologin
tomcat:x:10008:10008::/opt/cloudchef/tomcat:/sbin/nologin
test:x:10010:10010::/home/test:/bin/bash
test1:x:10011:10011::/home/test1:/bin/bash - 只查找test1用户
[root@Server-n93yom ~]# id test1
uid=10011(test1) gid=10011(dev) groups=10011(dev)
[root@Server-n93yom ~]#uid为用户id, gid为组id
- 修改和创建密码 passwd 用户名 如果不加用户名则默认修改当前登录者的密码
[root@Server-n93yom ~]# passwd test1
Changing password for user test1.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@Server-n93yom ~]#设置好密码后,使用此账号和密码登录
➜ ~ ssh test1@192.168.85.163
test1@192.168.85.163's password:
Last failed login: Mon Jul 22 17:00:05 CST 2019 from 192.168.1.53 on ssh:notty
There were 3 failed login attempts since the last successful login.
[test1@Server-n93yom ~]$ - 设置用户不能修改密码
[root@Server-n93yom ~]# passwd -l test1 //在root下,禁止test1用户修改密码的权限
Locking password for user test1. //锁住test1不能修改密码
passwd: Success
[root@Server-n93yom ~]# su test1 //切换用户
[test1@Server-n93yom root]$ passwd //修改密码
Changing password for user test1.
Changing password for test1.
(current) UNIX password:
passwd: Authentication token manipulation error //没用权限修改密码
[test1@Server-n93yom root]$ - 清除密码
[root@Server-n93yom ~]# passwd -d test1 //删除test1的密码
Removing password for user test1.
passwd: Success
[root@Server-n93yom ~]# passwd -S test1 //查看test1的密码
test1 NP 2019-07-22 0 99999 7 -1 (Empty password.) //密码为空
[root@Server-n93yom ~]# - passwd 帮助命令
[root@Server-n93yom ~]# passwd --help
Usage: passwd [OPTION...] <accountName>
-k, --keep-tokens keep non-expired authentication tokens
-d, --delete delete the password for the named account (root only)
-l, --lock lock the password for the named account (root only)
-u, --unlock unlock the password for the named account (root only)
-e, --expire expire the password for the named account (root only)
-f, --force force operation
-x, --maximum=DAYS maximum password lifetime (root only)
-n, --minimum=DAYS minimum password lifetime (root only)
-w, --warning=DAYS number of days warning users receives before password
expiration (root only)
-i, --inactive=DAYS number of days after password expiration when an account
becomes disabled (root only)
-S, --status report password status on the named account (root only)
--stdin read new tokens from stdin (root only) Help options:
-?, --help Show this help message
--usage Display brief usage message
[root@Server-n93yom ~]#
3.设置密码失效时间
- 可以编辑
/etc/login.defs来设定几个参数,以后设置口令默认就按照参数设定为准:PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7 当然在
/etc/default/useradd可以找到如下2个参数进行设置:# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes通过修改配置文件,能对之后新建用户起作用,而目前系统已经存在的用户,则直接用chage来配置。
chage [选项] 用户名
chage命令是用来修改帐号和密码的有效期限。
-m:密码可更改的最小天数。为零时代表任何时候都可以更改密码。
-M:密码保持有效的最大天数。
-w:用户密码到期前,提前收到警告信息的天数。
-E:帐号到期的日期。过了这天,此帐号将不可用。
-d:上一次更改的日期。
-i:停滞时期。如果一个密码已过期这些天,那么此帐号将不可用。
-l:例出当前的设置。由非特权用户来确定他们的密码或帐号何时过期。chage -l root 查root账号的信息
[root@Server-n93yom ~]# chage -l root
Last password change : Jul 22, 2019
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
[root@Server-n93yom ~]#chage -M 60 test 设置密码过期时间为60天
chage -I 5 test 设置密码失效时间为5天
- 以test1账号为例,再查一次信息账号信息
[root@Server-n93yom ~]# chage -l test1
Last password change : Jul 22, 2019
Password expires : Sep 20, 2019
Password inactive : Sep 25, 2019
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 60
Number of days of warning before password expires : 7从上述命令可以看到,在密码过期后5天,密码自动失效,这个用户将无法登陆系统了。
Linux添加用户组和添加用户的更多相关文章
- Linux添加、创建新用户
给Linux添加新用户,新建用户,新建帐号 添加用户组 sudo groupadd groupname 添加用户 sudo useradd username -m -s /bin/bash -d /h ...
- Linux用户组的添加及属性的更改
用户组的创建: 12345 groupadd [OPTION] 组名 -g GID 指明GID号:[GID_MIN, GID_MAX] -r 创建系统组 CentOS 6: ID<500 Cen ...
- Linux添加用户组和删除用户组
1.添加用户组使用groupadd命令添加用户组:groupadd group_name此操作需由系统管理员进行.2.删除用户组使用groupdel命令删除用户组:groupdel group_nam ...
- MVC4做网站后台:用户管理 ——用户组 1、添加用户组
打开控制器UserGroupController 添加Add action /// <summary> /// 添加用户组 /// </summary> /// <ret ...
- Linux 新建用户、用户组,给用户分配权限(chown、useradd、groupadd、userdel、usermod、passwd、groupdel)
Linux 系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统.用户的账号一方面可以帮助系统管理员对使用系统的用户进行 ...
- Linux常用命令学习8---(用户和用户组管理)
1.用户和用户组 用户和用户组概念 用户:使用操作系统的人(Linux支持多个用户在同一时间登陆同一个操作系统) 用户组:具有相同权限的一组用户(Linux系统中可 ...
- 烂泥:puppet添加带密码的用户
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 前一篇文章,我们介绍了有关puppet3.7的安装与配置,这篇文章我们再来介绍下如何利用puppet添加带密码的用户. 要通过puppet添加带密码的用 ...
- linux如何查看所有的用户(user)、用户组(group)、密码(password/passwd)
linux如何查看所有的用户和组信息_百度经验https://jingyan.baidu.com/article/a681b0de159b093b184346a7.html linux添加用户.用户组 ...
- Linux 开机、重启和用户登录注销、用户管理、用户组
l 关机&重启命令 基本介绍: shutdown –h now 立该进行关机 shudown -h 1 "hello, 1 分钟后会关机了" shutdown –r n ...
随机推荐
- 登陆认证框架:SpringSecurity
最近想给自己的小系统搭建一个登录认证服务,最初是想着一套oauth2权鉴就可以,但是发现这个oauth2只是权鉴,具体的登录认证需要由 SpringSecurity来进行实现. 也就是说SpringS ...
- getRequestDispatcher 中请求转发和请求包含的使用说明
getRequestDispatcher() getRequestDispatcher() 包含两个方法,分别是请求转发和请求包含. RequestDispatcher rd = request.ge ...
- 初识python: flush 实现进度条打印
通过flush(强制刷新)实现,类似进度条打印: #!/user/bin env python # author:Simple-Sir # time:20180918 #打印进度条 import sy ...
- 关闭SpringBoot logo图标
public static void main(String[] args) {// SpringApplication.run(LicenseApp.class, args); //关闭Spring ...
- spring boot 解决 跨域 的两种方法 -- 前后端分离
1.前言 以前做项目 ,基本上是使用 MVC 模式 ,使得视图与模型绑定 ,前后端地址与端口都一样 , 但是现在有些需求 ,需要暴露给外网访问 ,那么这就出现了个跨域问题 ,与同源原则冲突, 造成访问 ...
- Kube-OVN 0.6.0 发布,支持 IPv6、流量镜像及更多功能
Kube-OVN 是一个基于 OVN 的 Kubernetes 开源网络系统. 本次更新主要包含了以下内容: 1. 支持流量镜像 在安装 Kube-OVN 时可以开启 mirror 选项,会自动在每个 ...
- java 8 - java 17 升级指北
2014年发布的java SE 8和2017年发布的java EE 8,至今还是使用最广泛的java版本,大部分java开发者对于java 8之后的升级总是敬而远之,这跟java 9以后的破坏性升级和 ...
- Flink 非对齐Unaligned的checkpoint(源码分析)
本文源码基于flink1.14 在帮助用户排查任务的时候,经常会发现部分task处理的慢,在Exactly once语义时需要等待快照的对齐而白白柱塞的情况 在flink1.11版本引入了非对齐的ch ...
- PIKACHU之文件包含漏洞
PIKUCHU靶场之文件包含 一.file inclusion(local) 实验源码: <?php /** * Created by runner.han * There is nothing ...
- 【解决了一个小问题】golang的go.mod中出现版本错误
代码中的这一句使用prometheus2.28.0版本的代码: import "github.com/prometheus/prometheus/prompb" 我把require ...