加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

管理用户和组 day4 (20190930)

发布时间:2020-12-14 00:16:43 所属栏目:Linux 来源:网络整理
导读:管理用户和组 一、管理用户和组 用户: 1.登陆操作系统 2.不同的用户权限不同 组:方便管理用户 唯一标识: UID GID 管理员root的UID为0 组:基本组(私有组) 附加组(从属组) Linux一个用户至少属于一个组 基本组:由系统创建与用户同名的组 附加组:由管理
管理用户和组

一、管理用户和组

用户: 1.登陆操作系统 2.不同的用户权限不同
组:方便管理用户

唯一标识: UID GID
管理员root的UID为0

组:基本组(私有组) 附加组(从属组)
Linux一个用户至少属于一个组
基本组:由系统创建与用户同名的组
附加组:由管理员创建并且将用户加入

[[email?protected] /]# useradd abc
abc组
cw组 js组 sg组

1、添加用户

用户基本信息存放在 /etc/passwd 文件
[[email?protected] /]# head -1 /etc/passwd
root:x:0:0:root:/root:/bin/bash

? 使用 useradd 命令

– useradd [选项]... 用户名

? 常用命令选项

– -u 用户id、-d 家目录路径、-s 登录解释器、-G 附加组

建议:普通用户的UID从1000开始

[[email?protected] /]# useradd nsd01
[[email?protected] /]# id haha
id: haha: no such user
[[email?protected] /]# id nsd01 #查询用户基本信息

[[email?protected] /]# useradd -u 1500 nsd02 #指定UID创建
[[email?protected] /]# id nsd02

[[email?protected] /]# ls /home #查看生成的家目录

[[email?protected] /]# useradd nsd03
[[email?protected] /]# grep nsd /etc/passwd
用户名:密码占位符:UID:基本组GID:用户描述信息:家目录:解释器程序

[[email?protected] /]# ls /home

[[email?protected] /]# useradd -d /opt/nsd04 nsd04 #创建用户指定家目录
[[email?protected] /]# ls /opt/
[[email?protected] /]# grep nsd /etc/passwd

[[email?protected] /]# useradd -d /mnt/nsd05 nsd05
[[email?protected] /]# ls /mnt
[[email?protected] /]# grep nsd /etc/passwd

-s 登录解释器

/sbin/nologin:禁止用户登陆操作系统

[[email?protected] /]# useradd -s /sbin/nologin nsd06
[[email?protected] /]# grep nsd06 /etc/passwd

[[email?protected] /]# useradd -s /sbin/nologin nsd07
[[email?protected] /]# grep nsd07 /etc/passwd

-G 附加组

[[email?protected] /]# groupadd stugrp #创建组

[[email?protected] /]# useradd -G stugrp nsd08
[[email?protected] /]# id nsd08
uid=1504(nsd08) gid=1505(nsd08) 组=1505(nsd08),1504(stugrp)

[[email?protected] /]# useradd -G stugrp nsd09
[[email?protected] /]# id nsd09

[[email?protected] /]# useradd -G stugrp nsd10
[[email?protected] /]# id nsd10

? 使用 passwd 命令

3、修改用户属性

? 使用 usermod 命令

– usermod [选项]... 用户名

? 常用命令选项

– -u 用户id、-d 家目录路径、-s 登录解释器、 -G 附加组

[[email?protected] /]# useradd nsd11
[[email?protected] /]# id nsd11
[[email?protected] /]# grep nsd11 /etc/passwd

[[email?protected] /]# usermod -u 1600 -d /mnt/nsd11 -s /sbin/nologin -G stugrp nsd11

[[email?protected] /]# id nsd11
[[email?protected] /]# grep nsd11 /etc/passwd

[[email?protected] /]# useradd nsd12
[[email?protected] /]# id nsd12
[[email?protected] /]# grep nsd12 /etc/passwd

[[email?protected] /]# usermod -u 1700 -d /mnt/nsd12 -s /sbin/nologin -G stugrp nsd12
[[email?protected] /]# id nsd12
[[email?protected] /]# grep nsd12 /etc/passwd

四、删除用户

? 使用 userdel 命令

– userdel 用户名

[-r]:连同家目录一并删除

[[email?protected] /]# userdel nsd01
[[email?protected] /]# ls /home/
[[email?protected] /]# userdel -r nsd02
[[email?protected] /]# ls /home/

五、管理组账号

添加组

组基本信息存放在 /etc/group 文件
[[email?protected] /]# grep tarena /etc/group
tarena:x:1602:

? 使用 groupadd 命令
– groupadd [-g 组ID] 组名

[[email?protected] /]# groupadd tarena
[[email?protected] /]# grep tarena /etc/group
tarena:x:1602:

[[email?protected] /]# useradd haha
[[email?protected] /]# useradd xixi
[[email?protected] /]# useradd dc
[[email?protected] /]# useradd tc

管理组成员

? 使用 gpasswd 命令
– gpasswd -a 用户名 组名
– gpasswd -d 用户名 组名

[[email?protected] /]# gpasswd -a haha tarena #将用户haha加入到组
[[email?protected] /]# grep tarena /etc/group #查看组成员信息

[[email?protected] /]# gpasswd -a xixi tarena #将用户xixi加入到组
[[email?protected] /]# grep tarena /etc/group #查看组成员信息

[[email?protected] /]# gpasswd -a dc tarena #将用户dc从组中删除
[[email?protected] /]# grep tarena /etc/group #查看组成员信息

[[email?protected] /]# gpasswd -d xixi tarena #将用户xixi从组中删除
[[email?protected] /]# grep tarena /etc/group #查看组成员信息

[[email?protected] /]# gpasswd -d haha tarena #将用户haha从组中删除
[[email?protected] /]# grep tarena /etc/group #查看组成员信息

[[email?protected] /]# gpasswd -d dc tarena #将用户dc从组中删除
[[email?protected] /]# grep tarena /etc/group #查看组成员信息

删除组:不能删除用户的基本组

[[email?protected] /]# groupdel tarena
[[email?protected] /]# grep tarena /etc/group

六、tar备份与恢复

1.将零散分散的数据,归档成一个文件
2.节省空间

? 归档的含义

– 将许多零散的文件整理为一个文件
– 文件总的大小基本不变

? 压缩的含义

– 按某种算法减小文件所占用空间的大小
– 恢复时按对应的逆向算法解压

Linux平台压缩格式:

gzip------>.gz
  bzip2------>.bz2
  xz------>.xz

? tar 集成备份工具(打包)

– -c:创建归档
– -x:释放归档
– -f:指定归档文件名称,必须放在所有的选项后面
– -z、-j、-J:调用 .gz、.bz2、.xz 格式的工具进行处理
– -t:显示归档中的文件清单
– -C:指定释放路径

tar打包格式:

命令格式:tar 选项 /路径/压缩包名字 /路径/源数据.......

—利用gzip进行压缩
]# tar -zcf /mnt/abc.tar.gz /etc/passwd /home/
]# ls /mnt/
—利用bzip2进行压缩
]# tar -jcf /mnt/nsd.tar.bz2 /etc/passwd /home/
]# ls /mnt/
—利用xz进行压缩
]# tar -Jcf /mnt/stu.tar.xz /etc/passwd /home/
]# ls /mnt/

tar解包格式:

命令格式:tar 选项 /路径/压缩包名字 选项 /释放的路径

[[email?protected] /]# mkdir /tar01
[[email?protected] /]# tar -xf /mnt/abc.tar.gz -C /tar01
[[email?protected] /]# ls /tar01/
[[email?protected] /]# ls /tar01/etc/
[[email?protected] /]# ls /tar01/home/

[[email?protected] /]# mkdir /tar02
[[email?protected] /]# tar -xf /mnt/nsd.tar.bz2 -C /tar02
[[email?protected] /]# ls /tar02/
[[email?protected] /]# ls /tar02/etc/
[[email?protected] /]# ls /tar02/home/

[[email?protected] /]# mkdir /tar03
[[email?protected] /]# tar -xf /mnt/stu.tar.xz -C /tar03
[[email?protected] /]# ls /tar03/
[[email?protected] /]# ls /tar03/etc/
[[email?protected] /]# ls /tar03/home/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读