linux系统创建用户、调整权限及用户和用户组id(centos 9 stream)_centos9 创建用户

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Linux运维全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注运维)
img

正文

[root@n2 munge]# adduser
Usage: adduser [options] LOGIN
adduser -D
adduser -D [options]

Options:
–badname do not check for bad names
-b, --base-dir BASE_DIR base directory for the home directory of the
new account
–btrfs-subvolume-home use BTRFS subvolume for home directory
-c, --comment COMMENT GECOS field of the new account
-d, --home-dir HOME_DIR home directory of the new account
-D, --defaults print or change default useradd configuration
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity period of the new account
-g, --gid GROUP name or ID of the primary group of the new
account
-G, --groups GROUPS list of supplementary groups of the new
account
-h, --help display this help message and exit
-k, --skel SKEL_DIR use this alternative skeleton directory
-K, --key KEY=VALUE override /etc/login.defs defaults
-l, --no-log-init do not add the user to the lastlog and
faillog databases
-m, --create-home create the user’s home directory
-M, --no-create-home do not create the user’s home directory
-N, --no-user-group do not create a group with the same name as
the user
-o, --non-unique allow to create users with duplicate
(non-unique) UID
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-R, --root CHROOT_DIR directory to chroot into
-P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as the user
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping


 系统的help信息已经比较全了,简单翻译一下,不懂英文的就网络翻译一下吧。


### 1、创建用户



###创建用户名为zhangshan的用户,默认这样创建会自动顺序配置uid,gid,home目录等,因此有可能出现uid与gid不相等情况。
useradd zhangsan
#默认情况下会自动创建zhangshan用户对应的用户组
id zhangshan

[root@n2 munge]# id zhangshan
uid=1000(zhangshan) gid=1000(zhangshan) groups=1000(zhangshan)

###在特殊情况下我们只需要创建系统用户,不需要登陆,不需要建立用户home目录
useradd -s /sbin/nologin slurm

###指定uid编号
useradd -u 1000 zhangshan

###指定用户目录,默认在/home/zhangshan
useradd -d /home/zhangshan zhangshan

###指定用户组,-g使用现有用户组,-G创建zhangshan用户组并将zhangshan用户加入用户组
useradd -g root zhangshan
useradd -G root zhangshan

###比较完整的创建,一般不需要这样指定。
useradd -s /bin/bash -m -d /home/zhangshan -g zhangshan zhangshan

###批量创建用户
newusers usersfilename.txt

##usersfilename.txt内容
#loginname:password:uid:gid:comment:home_dir:shell

zhangshan:zhangshanmima2234:1020:1001:Zhangshan Yonghu:/home/zhangshan:/bin/bash
lisi:lisidemima:1021:1001:Lisi Yonghu:/home/lisi:/bin/bash
wangwu:wangwu2234:1022:1001:Wangwu Yonghu:/home/wangwu:/bin/bash


### 


### 2、设置密码



password zhangshan

Changing password for user zhangshan.
New UNIX password: //在这里输入新密码
Retype new UNIX password: //再次输入新密码
passwd: all authentication tokens updated successfully.


直接输入两次相同密码即可。


### 3、用户权限调整


让普通用户具有管理员所有权限



###方法1
vim /etc/sudoers
root ALL=(ALL) ALL
zhangshan ALL=(ALL) ALL

###方法2,将用户组设置为root,并将/etc/sudoers中的%wheel 这行去掉注释
usermod -g root zhangshan

vim /etc/sudoers
%wheel ALL=(ALL) ALL

#此方法会改变用户用户组,个人不建议

###修改/etc/passwd文件,将指定用户id设置为0
#个人不推荐。


### 4、调整用户ID和用户组ID


在linux集群中为保证不同集群中各节点系统用户权限保持一致,将所有节点相同服务的用户名uid及gid设置为一致非常重要,尤其是在不同节点共享数据目录时,各节点服务uid和gid的不同会导致部分节点服务不可用。



###普通用户调整uid及gid
usermod -u 2898 zhangshan

groupmod -g 2898 zhangshan
usermod -g 2898 zhangshan

chown -R zhangshan:zhangshan /home/zhangshan

###调整系统用户mungeid为1899
#如为系统用户,要先停止用户相关服务进程
systemctl stop munge
#修改munge用户id为1899
usermod -u 1899 munge
#修改munge用户用户组id为1899

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注运维)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注运维)**
[外链图片转存中…(img-lU6L166z-1713372061106)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 21
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值