Linux运维系统工程师系列01

本文发布时间: 2019-Mar-22
windows里administrator用户是什么?用户是用来操作系统中不同功能的身份Linux中用户的分类:1)root:超级用户2)系统用户:bin---系统命令的属主daemon-----无特权系统软件的属主nobody------普通的nfs的用户3)普通用户:管理员创建的用户组:group用户和组的关系:如果以公司比作linux系统,部门相当于组,部门里的员工相当于用户。组里可以没有用户,可以有一个用户,也可以有多个用户。和用户相关的一些命令:useradd或者adduser-----添加用户usermod -----修改用户属性userdel-------删除用户id-------------查看用户信息mod----modify修改del------delete删除passwd-------设置密码注意:添加用户的操作需要root用户来做添加用户举例[root@localhost tmp]# useradd niulang查看用户信息[root@localhost tmp]# id niulanguid=501(niulang) gid=501(niulang) groups=501(niulang)--uid:user id用户标识uid为0,表示的是超级用户--gid:group id:表示用户primary group的id--groups:用户所属组的信息如果添加用户时不指定组,那么会创建一个和用户同名的组。添加用户时指定选项:-c:comment(注释),描述信息-d:用户的家目录/root:是root用户的家目录/home:默认情况下是普通用户家目录所在处如果创建用户时没有加-d选项指定家目录,那么它的家目录就是/home下和用户名同名的一个目录。例如:/home/niulang-g:指定用户的主要组 在指定的时候可以用ID或者是组名字,有一个前提,就是这个组必须是存在的。-G:指定用户的附加组 在指定的时候可以用ID或者是组名字,有一个前提,就是这个组必须是存在的。-s:指定用户的登录shell-u:指定用户的uiduseradd 选项 选项的参数 ... 用户名[root@localhost ~]# useradd -g 500 zhinv[root@localhost ~]# id zhinvuid=502(zhinv) gid=500(u1) groups=500(u1)[root@localhost ~]# useradd -g niulang wangmu[root@localhost ~]# id wangmuuid=503(wangmu) gid=501(niulang) groups=501(niulang)反例:组必须是存在的[root@localhost ~]# useradd -g 503 yhdduseradd: group '503' does not exist[root@localhost ~]# head -5 /etc/passwdroot:x:0:0:root:/root:/bin/bash用户:密码:uid:gid:描述信息:家目录:登录shell何为shell?shell是一个命令解释器。提供人机交互的程序。/bin :下面存放的是基本命令,bin是binary的前三个字母一个用户有且只有一个主组。但是可以属于多个组,其他组为附加组。删除用户[root@localhost ~]# userdel stu01[root@localhost ~]# id stu01id: stu01: No such user[root@localhost ~]# useradd stu01useradd: warning: the home directory already exists.Not copying any file from skel directory into it.Creating mailbox file: File exists[root@localhost ~]# id stu01uid=510(stu01) gid=510(stu01) groups=510(stu01)-r :递归删除,会同时删除用户的家目录[root@localhost mail]# userdel -r u8[root@localhost mail]# ls /home/niulang stu01 stu03 stu04 stu05 u1 wangmu zhinv/sbin:管理类命令,外部命令stu01:x:510:510::/home/stu01:/bin/bash-u -g -c -d -s修改用户常用选项usermod :-d:修改用户家目录-g:修改用户的主组-G:修改用户的附加组,不管你原来的附加组是什么[root@localhost mail]# usermod -d /tmp/stu01 stu01[root@localhost mail]# tail -1 /etc/passwdstu01:x:510:510::/tmp/stu01:/bin/bash[root@localhost mail]# usermod -g stu05 stu01[root@localhost mail]# id stu01uid=510(stu01) gid=508(stu05) groups=508(stu05)[root@localhost mail]# usermod -G stu04,stu01 stu01[root@localhost mail]# id stu01uid=510(stu01) gid=508(stu05) groups=508(stu05),507(stu04),510(stu01)如果你原来没有设置附加组,直接将你-G后面的组加到附加组里。如果你原来设置了附加组,则修改附加组主组不受影响[root@localhost mail]# useradd stu08[root@localhost mail]# id stu08uid=511(stu08) gid=511(stu08) groups=511(stu08)[root@localhost mail]# usermod -G stu05 stu08[root@localhost mail]# id stu08uid=511(stu08) gid=511(stu08) groups=511(stu08),508(stu05)[root@localhost mail]# id stu01uid=510(stu01) gid=508(stu05) groups=508(stu05),507(stu04),510(stu01)[root@localhost mail]# usermod -G u1 stu01[root@localhost mail]# id stu01uid=510(stu01) gid=508(stu05) groups=508(stu05),500(u1)-a:追加组[root@localhost mail]# usermod -a -G niulang stu01[root@localhost mail]# id stu01uid=510(stu01) gid=508(stu05) groups=508(stu05),500(u1),501(niulang)-L:锁定账户[root@localhost mail]# passwd u1Changing password for user u1.New password:BAD PASSWORD: it is based on a dictionary wordBAD PASSWORD: is too simpleRetype new password:passwd: all authentication tokens updated successfully.[root@localhost mail]# usermod -L u1【Ctrl】+【Alt】+F2 切换到另一个终端输入用户名,密码,正常情况下会出现Login incorrect验证完之后,按【Alt】+F7或者【Alt】+F1回到图形界面-U:解锁用户[root@localhost mail]# usermod -U u1继续使用上述方法验证是否能够登录系统,如果能登录,证明成功-l:修改用户名 login name[root@localhost mail]# id stu08uid=511(stu08) gid=511(stu08) groups=511(stu08),508(stu05)[root@localhost mail]# usermod -l stu80 stu08[root@localhost mail]# id stu08id: stu08: No such user[root@localhost mail]# id stu80uid=511(stu80) gid=511(stu08) groups=511(stu08),508(stu05)-u:修改uid[root@localhost mail]# usermod -u 520 stu80[root@localhost mail]# id stu80uid=520(stu80) gid=511(stu08) groups=511(stu08),508(stu05)给用户改密码passwd超级用户:可以改别人的密码普通用户:只能改自己密码passwd不加任何东西,改当前用户密码[root@localhost mail]# passwdChanging password for user root.New password: redhatBAD PASSWORD: it is based on a dictionary wordBAD PASSWORD: is too simpleRetype new password: redhatpasswd: all authentication tokens updated successfully.root用户给其他用户改密码[root@localhost mail]# passwd u1Changing password for user u1.New password:BAD PASSWORD: it is based on a dictionary wordBAD PASSWORD: is too simpleRetype new password:passwd: all authentication tokens updated successfully.切换用户[root@localhost mail]# su - u1[u1@server254 ~]$ passwd stu07passwd: Only root can specify a user name.指定/etc/passwd文件:存放用户信息的文件


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:10pm
栏目列表