素材来源:Redhat Linux 8.0培训教材《RH124》、《RH134》和《RH294》
玩了5-6年的Linux,现在再来温习一遍RHCE培训教材,按照指导完成实验并与大家分享。
附上汇总贴:玩转Redhat Linux 8.0系列 | 合集_热爱编程的通信人的博客-CSDN博客
1 使用ssh命令, 以student用户身份登录servera。
[student@workstation ~]$ ssh student@servera
student@servera's password:
Activate the web console with: systemctl enable --now cockpit.socket
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
Last login: Sun May 21 19:35:28 2023 from 172.16.190.227
[student@servera ~]$
2 使用su命令, 并将redhat用作密码, 切换到operator1用户。
[student@servera ~]$ su - operator1
Password:
[operator1@servera ~]$
3 使用umask命令, 列出operator1用户的默认umask值。
[operator1@servera ~]$ umask
0002
[operator1@servera ~]$
4 创建一个名为/tmp/shared的新目录。在/tmp/shared目录中, 创建一个名为defaults的文件。查看其默认权限。
4.1 使用mkdir命令来创建/tmp/shared目录。使用ls -ld命令列出新目录的权限。
[operator1@servera ~]$ mkdir /tmp/shared
[operator1@servera ~]$ ls -ld /tmp/shared
drwxrwxr-x. 2 operator1 operator1 6 May 21 19:53 /tmp/shared
[operator1@servera ~]$
4.2 使用touch命令, 在/tmp/shared目录中创建一个名为defaults的文件。
[operator1@servera ~]$ touch /tmp/shared/defaults
[operator1@servera ~]$
4.3 使用ls -l命令列出新文件的权限。
[operator1@servera ~]$ ls -l /tmp/shared/defaults
-rw-rw-r--. 1 operator1 operator1 0 May 21 19:53 /tmp/shared/defaults
[operator1@servera ~]$
5 将/tmp/shared的组所有权更改给operators。确认新的所有权和权限。
5.1 使用chown命令, 将/tmp/shared目录的组所有权更改给operators。
[operator1@servera ~]$ chown :operators /tmp/shared
[operator1@servera ~]$
5.2 使用ls -ld命令列出/tmp/shared目录的权限。
[operator1@servera ~]$ ls -ld /tmp/shared
drwxrwxr-x. 2 operator1 operators 22 May 21 19:53 /tmp/shared
[operator1@servera ~]$
5.3 使用touch命令, 在/tmp/shared目录中创建一个名为group的文件。使用ls -l命令列出其文件权限。
[operator1@servera ~]$ touch /tmp/shared/group
[operator1@servera ~]$ ls -l /tmp/shared/group
-rw-rw-r--. 1 operator1 operator1 0 May 21 19:56 /tmp/shared/group
[operator1@servera ~]$
6 确保在/tmp/shared目录中创建的文件归operators组所有。
6.1 使用chmod命令, 将/tmp/shared目录的组ID设置为operators组。
[operator1@servera ~]$ chmod g+s /tmp/shared
[operator1@servera ~]$
6.2 使用touch命令,在/tmp/shared目录中创建一个名为operations_database.txt的新文件。
[operator1@servera ~]$ touch /tmp/shared/operations_database.txt
[operator1@servera ~]$
6.3 使用ls -l命令, 验证operators组是新文件的组所有者。
[operator1@servera ~]$ ls -l /tmp/shared/operations_database.txt
-rw-rw-r--. 1 operator1 operators 0 May 21 19:58 /tmp/shared/operations_database.txt
[operator1@servera ~]$
7 在/tmp/shared目录中创建一个新文件, 取名为operations_network.txt。记录其所有权和权限。更改operator1的umask。创建一个名为operations_production.txt的新文件。记录operations_production.txt文件的所有权和权限。
7.1 使用echo命令, 在/tmp/shared目录中创建一个名为operations_network.txt的文件。
[operator1@servera ~]$ echo text >> /tmp/shared/operations_database.txt
[operator1@servera ~]$
7.2 使用ls -l命令,列出operations_network.txt文件的权限。
[operator1@servera ~]$ ls -l /tmp/shared/operations_database.txt
-rw-rw-r--. 1 operator1 operators 5 May 21 20:00 /tmp/shared/operations_database.txt
[operator1@servera ~]$
7.3 使用umask命令, 将operator1用户的umask更改为027。使用umask命令确认更改。
[operator1@servera ~]$ umask 027
[operator1@servera ~]$ umask
0027
[operator1@servera ~]$
7.4 使用touch命令, 在/tmp/shared/目录中创建一个名为operations_production.txt的新文件。使用ls -l命令, 确保在创建新创建的文件时使operators组拥有只读访问权限, 其他用户没有访问权限。
[operator1@servera ~]$ touch /tmp/shared/operations_production.txt
[operator1@servera ~]$ ls -l /tmp/shared/operations_production.txt
-rw-r-----. 1 operator1 operators 0 May 21 20:03 /tmp/shared/operations_production.txt
[operator1@servera ~]$
8 打开一个新的终端窗口, 并以operator1用户身份登录servera。
[student@workstation ~]$ ssh operator1@servera
operator1@servera's password:
Activate the web console with: systemctl enable --now cockpit.socket
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
Last login: Sun May 21 19:52:03 2023
[operator1@servera ~]$
9 列出operator1的umask值。
[operator1@servera ~]$ umask
0002
[operator1@servera ~]$
10 更改operator1用户的默认umask。新umask将阻止不属于其组的用户的所有访问权限。确认umask已被更改。
10.1 使用echo命令, 将operator1用户的umask更改为007。
[operator1@servera ~]$ echo "umask 007" >> ~/.bashrc
[operator1@servera ~]$ cat ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
umask 007
[operator1@servera ~]$
10.2 注销, 然后重新以operator1用户身份登录。使用umask命令确认更改是否持久。
[operator1@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation ~]$ ssh operator1@servera
operator1@servera's password:
Activate the web console with: systemctl enable --now cockpit.socket
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
Last login: Sun May 21 20:05:25 2023 from 172.16.190.227
[operator1@servera ~]$ umask
0007
[operator1@servera ~]$
11 在servera上, 从所有operator1和student用户的shell退出。
[operator1@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation ~]$