Linux系统管理——用户操作

一、用户相关介绍

多用户多任务操作系统

1、用户类型

  • 管理员 root , uid=0
  • 普通用户
  • 系统用户, 保证某个软件/应用可正常运行; uid=1–999

2、用户相关文件

  • /etc/passwd 用户信息
// 统计用户数
[root@martin-host ~]# wc -l /etc/passwd | awk '{print $1}'
48
// 文件格式 
用户名:x:uid:gid:说明信息:家目录:shell

操作系统使用uid区分不同的用户
用户组:基本组(一个)、附加组(多个)
shell:
/bin/bash:默认shell, 可正常登录系统、执行操作
/sbin/nologin: 不允许与系统进行交互 
  • /etc/shadow 用户密码信息

  • /etc/group 用户组信息

二、用户操作

1、创建用户

# useradd [选项] 用户名 
  • -s 指定用户shell, 默认/bin/bash
[root@martin-host ~]# useradd -s /sbin/nologin www 
[root@martin-host ~]# 
[root@martin-host ~]# grep "www" /etc/passwd 
www:x:1004:1004::/home/www:/sbin/nologin
  • -M 不创建家目录, 系统用户
[root@martin-host ~]# useradd -s /sbin/nologin -M docker
  • -r 创建系统用户
[root@martin-host ~]# useradd -r -s /sbin/nologin -M redis
[root@martin-host ~]# 
[root@martin-host ~]# tail -n 1 /etc/passwd 
redis:x:986:980::/home/redis:/sbin/nologin
[root@martin-host ~]# 
[root@martin-host ~]# ls /home/
AAA  BBB  demon  martin  www
[root@martin-host ~]# 
  • -G 指定用户的附加组
[root@martin-host ~]# groupadd IT
[root@martin-host ~]# useradd -G IT tome 
[root@martin-host ~]# 
[root@martin-host ~]# id tome 
uid=1006(tome) gid=1007(tome)=1007(tome),1006(IT)
[root@martin-host ~]# 
[root@martin-host ~]# grep -i "it" /etc/group 
polkitd:x:998:
rtkit:x:172:
gnome-initial-setup:x:982:
IT:x:1006:tome
[root@martin-host ~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值