用户和用户组练习
目录
1、创建mygroup组群,再创建myuser用户,并且此用户属于mygroup组群,接着以myuser身份登 录,创建ex和hv两个文件于/home/myuser目录,并使hv文件的同组用户是root。请依次写出相应执行 的命令。
2、现需添加一新用户helen并设置其用户主目录/helen,密码为空。还需添加新组群temp,指定其 GID为600,并将temp组群作为用户helen的附加组群。请依次写出相应执行的命令。
3、创建用户user,并设置其口令为“a1b2c3”,并加入group组群(假设group组群已经存在)。请依次 写出相应执行的命令。
4、新建一个名为adminuser的组,组id为40000
5、新建一个名为natasha的用户,并将adminuser作为其附属组
6、新建一个名为sarah的用户,并将其shell设置为不可登陆shell
7、natasha、harry和sarah三个用户的密码均设置为glegunge创建用户
8、使alex用户满足以下要求:用户id为3456,描述名为alian密码为glegunge
9、创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt
1、创建mygroup组群,再创建myuser用户,并且此用户属于mygroup组群,接着以myuser身份登 录,创建ex和hv两个文件于/home/myuser目录,并使hv文件的同组用户是root。请依次写出相应执行 的命令。
groupadd mygroup
useradd -g mygroup myuser
[root@localhost home]# su - myuser
[myuser@localhost ~]$ touch hv ex
[myuser@localhost ~]$ ll
total 0
-rw-r--r--. 1 myuser mygroup 0 Apr 10 19:36 ex
-rw-r--r--. 1 myuser mygroup 0 Apr 10 19:36 hv[myuser@localhost ~]$ chown :root hv
chown: changing group of 'hv': Operation not permitted
myuser没有权限,给权限
[myuser@localhost ~]$ su - root
Password:
[root@localhost ~]# vim /etc/sudoers
myuser ALL=(ALL) NOPASSWD:ALL[root@localhost ~]# su - myuser
[myuser@localhost ~]$ sudo chown :root hv
[myuser@localhost ~]$ ll
total 0
-rw-r--r--. 1 myuser mygroup 0 Apr 10 19:36 ex
-rw-r--r--. 1 myuser root 0 Apr 10 19:36 hv
2、现需添加一新用户helen并设置其用户主目录/helen,密码为空。还需添加新组群temp,指定其 GID为600,并将temp组群作为用户helen的附加组群。请依次写出相应执行的命令。
方法1:先创建用户
[root@localhost ~]# useradd -d /helen helen
[root@localhost ~]# groupadd -g 600 temp[root@localhost ~]# id helen
uid=1003(helen) gid=1003(helen) groups=1003(helen)[root@localhost ~]# gpasswd -a helen temp
Adding user helen to group temp[root@localhost ~]# id helen
uid=1003(helen) gid=1003(helen) groups=1003(helen),600(temp)
方法2:先创建组
[root@localhost ~]# groupadd -g 600 temp
[root@localhost ~]# useradd helen -d /helen -G temp
[root@localhost helen]# id helen
uid=1003(helen) gid=1003(helen) groups=1003(helen),600(temp)
3、创建用户user,并设置其口令为“a1b2c3”,并加入group组群(假设group组群已经存在)。请依次 写出相应执行的命令。
[root@localhost ~]# useradd user -G group
[root@localhost ~]# id user
uid=1004(user) gid=1005(user) groups=1005(user),1004(group)#也可以在创建用户的时候用-p指定密码,但是密码要是密文的
[root@localhost ~]# echo "a1b2b3" | passwd --stdin user [root@localhost ~]# tail -3 /etc/shadow
myuser:!!:19457:0:99999:7:::
helen:!!:19457:0:99999:7:::
user:$y$j9T$yJJuyzQ05IguhHelVrDXN0$5WX6AhFbgVb7XMxmaEjMACAFni1HKKbAbgRUDbj3fj4:19457:0:99999:7:::
4、新建一个名为adminuser的组,组id为40000
[root@localhost ~]# groupadd -g 2000 adminuser[root@localhost ~]# tail -2 /etc/group
user:x:1005:
adminuser:x:2000:
5、新建一个名为natasha的用户,并将adminuser作为其附属组
[root@localhost ~]# useradd natasha -G adminuser
[root@localhost ~]# id natasha
uid=1005(natasha) gid=2001(natasha) groups=2001(natasha),2000(adminuser)
6、新建一个名为sarah的用户,并将其shell设置为不可登陆shell
useradd sarah -s /sbin/nolgin
7、natasha、harry和sarah三个用户的密码均设置为glegunge创建用户
echo "glegunge" | passwd --stdin 用户名
8、使alex用户满足以下要求:用户id为3456,描述名为alian密码为glegunge
[root@localhost ~]# useradd -u 3456 -c alina alex[root@localhost ~]# tail -2 /etc/passwd
natasha:x:1005:2001::/home/natasha:/bin/bash
alex:x:3456:3456:alina:/home/alex:/bin/bash[root@localhost ~]# passwd alex
Changing password for user alex.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.[root@localhost ~]# tail -2 /etc/shadow
natasha:!!:19457:0:99999:7:::
alex:$y$j9T$mzHLeqU6VUFRjrunrOW5/.$LxIMtUEUVtAg4Aa6YL8/HkOAyYuJO8pV7iYsxlKwHjD:19457:0:99999:7:::
[root@localhost ~]#
9、创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt
[root@localhost ~]# groupadd g1
[root@localhost ~]# touch redhat.txt
[root@localhost ~]# ll
drwxr-xr-x. 2 root root 6 Feb 9 18:21 Public
-rw-r--r--. 1 root root 0 Apr 10 20:43 redhat.txt[root@localhost ~]# chown redhat:g1 redhat.txt
[root@localhost ~]# ll
total 16drwxr-xr-x. 2 root root 6 Feb 9 18:21 Public
-rw-r--r--. 1 redhat g1 0 Apr 10 20:43 redhat.txt