目录
(2)在临时目录test下创建五个文件,文件名分别为passwd,group,bashrc,profile,sshd_config;
(3)在/test创建/etc/motd的软链接,文件名为motd.soft;
(1)将系统内核版本信息,发行版本信息,写入到/test/motd.soft文件中
(2)将当前主机主机名,当前用户使用的shell信息追加到/test/motd.hard文件中
(3)将根目录下的文件的文件名写入/test/file文件中
(4)查看当前工作目录是否为/test目录,将当前工作目录的详细信息追加到/test/file文件中
(1)将当前时间添加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中
(2)将当前用户的用户名追加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中
(1)将/etc/passwd文件内容读入/test/passwd,并修改文件里的root字符为admin
(2)将/etc/group文件内容读入/test/group,只保留root开头的行内容
(3)将/root/.bashrc文件内容读入/test/bashrc,删除#号开头的行内容
(4)将/etc/ssh/sshd_config文件内容读入/test/sshd_config,在该文件的第17行后添加一行内容 Port 22
(5)将/test/sshd_config文件中的第40-50行的yes改为no
(6)将/test/sshd_config文件另存为/test/sshd.conf
(7)将/test目录下的passwd,group,bashrc文件中的第一行内容复制至文档最后一行
(8)将/test目录下的profile,sshd_config文件中前两行内容复制至文档倒数第二行
一、第2章思维导图总结
二、第3章思维导图总结
三、第4章思维导图总结
四、第四章课后题
1、创建文件命令练习:
(1)在/目录下创建一个临时目录test;
(2)在临时目录test下创建五个文件,文件名分别为passwd,group,bashrc,profile,sshd_config;
(3)在/test创建/etc/motd的软链接,文件名为motd.soft;
创建/etc/motd的硬链接为motd.hard
2、重定向练习:
(1)将系统内核版本信息,发行版本信息,写入到/test/motd.soft文件中
[root@localhost test]# cat /etc/redhat-release 1> motd.soft
[root@localhost test]# uname -r >> motd.soft
[root@localhost test]# cat motd.soft
Red Hat Enterprise Linux release 8.5 (Ootpa)
4.18.0-348.el8.x86_64
(2)将当前主机主机名,当前用户使用的shell信息追加到/test/motd.hard文件中
[root@localhost test]# cat /etc/hostname > motd.hard
[root@localhost test]# echo $SHELL >> motd.hard
[root@localhost test]# cat motd.hard
localhost.localdomain
/bin/bash
(3)将根目录下的文件的文件名写入/test/file文件中
[root@localhost test]# ls / > /test/file
[root@localhost test]# cat /test/file
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
test
tmp
usr
var
(4)查看当前工作目录是否为/test目录,将当前工作目录的详细信息追加到/test/file文件中
[root@localhost test]# pwd
/test
[root@localhost test]# pwd >> /test/file
[root@localhost test]# cat /test/file
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
test
tmp
usr
var
/test
3、tee命令练习:
(1)将当前时间添加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中
[root@localhost test]# date | tee passwd group bashrc profile sshd_config
Sun Aug 21 21:11:10 CST 2022
[root@localhost test]# cat passwd
Sun Aug 21 21:11:10 CST 2022
[root@localhost test]# cat group
Sun Aug 21 21:11:10 CST 2022
[root@localhost test]# cat bashrc
Sun Aug 21 21:11:10 CST 2022
[root@localhost test]# cat profile
Sun Aug 21 21:11:10 CST 2022
[root@localhost test]# cat sshd_config
Sun Aug 21 21:11:10 CST 2022
(2)将当前用户的用户名追加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中
[root@localhost test]# cat /etc/hostname | tee -a passwd group bashrc profile sshd_config
localhost.localdomain
[root@localhost test]# cat passwd
Sun Aug 21 21:11:10 CST 2022
localhost.localdomain
[root@localhost test]# cat group
Sun Aug 21 21:11:10 CST 2022
localhost.localdomain
[root@localhost test]# cat bashrc
Sun Aug 21 21:11:10 CST 2022
localhost.localdomain
[root@localhost test]# cat profile
Sun Aug 21 21:11:10 CST 2022
localhost.localdomain
[root@localhost test]# cat sshd_config
Sun Aug 21 21:11:10 CST 2022
localhost.localdomain
4、vim命令练习:
(1)将/etc/passwd文件内容读入/test/passwd,并修改文件里的root字符为admin
[root@localhost ~]# vim /test/passwd
vim /test/passwd
:r /etc/passwd
:%s/root/admin/g
:wq
[root@localhost ~]# vim /test/passwd
Sun Aug 21 21:11:10 CST 2022
admin:x:0:0:admin:/admin:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/admin:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
(2)将/etc/group文件内容读入/test/group,只保留root开头的行内容
[root@localhost ~]# vim /test/group
vim /test/group
:r /etc/group:不是root开头的行号,不是root开头的行号 d
:wq
[root@localhost ~]# vim /test/group
root:x:0:
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"/test/group" 1L, 10C 1,1 All
(3)将/root/.bashrc文件内容读入/test/bashrc,删除#号开头的行内容
:r /root/.bashrc
光标放到#开头的行,按dd删除
:wq
[root@localhost ~]# vim /test/bashrc
Sun Aug 21 21:11:10 CST 2022
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
localhost.localdomain
~
~
~
~
~
~
8,1 All
(4)将/etc/ssh/sshd_config文件内容读入/test/sshd_config,在该文件的第17行后添加一行内容 Port 22
:r /etc/ssh/sshd_config
:set nu
进入编辑模式输入
[root@localhost ~]# vim /test/sshd_config
10 # OpenSSH is to specify options with their default value where 11 # possible, but leave them commented. Uncommented options overrid e the
12 # default value. 13
14 # If you want to change the port on a SELinux system, you have to tell
15 # SELinux about this change.
16 # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
17 #
18 Port 22
(5)将/test/sshd_config文件中的第40-50行的yes改为no
:set nu
:40,50 s/yes/no/g
[root@localhost ~]# vim /test/sshd_config
39 SyslogFacility AUTHPRIV
40 #LogLevel INFO
41
42 # Authentication:
43
44 #LoginGraceTime 2m
45 PermitRootLogin no
46 #StrictModes no
47 #MaxAuthTries 6
48 #MaxSessions 10
49
50 #PubkeyAuthentication no
(6)将/test/sshd_config文件另存为/test/sshd.conf
输入:w /test/sshd.conf
[root@localhost test]# ls
bashrc group motd.soft profile sshd_config
file motd.hard passwd sshd.conf
(7)将/test目录下的passwd,group,bashrc文件中的第一行内容复制至文档最后一行
分别在vim 三个文件下输入 :1 co 最后一行行号
[root@localhost ~]# vim /test/bashrc
1 Sun Aug 21 21:11:10 CST 2022
2
3
4 alias rm='rm -i'
5 alias cp='cp -i'
6 alias mv='mv -i'
7
8 if [ -f /etc/bashrc ]; then
9 . /etc/bashrc
10 fi
11 localhost.localdomain
12 Sun Aug 21 21:11:10 CST 2022
(8)将/test目录下的profile,sshd_config文件中前两行内容复制至文档倒数第二行
分别在两个vim 文件下输入 :1,2 co 文档倒数第二行行号
1 Sun Aug 21 21:11:10 CST 2022
2 # $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
148 Sun Aug 21 21:11:10 CST 2022
149 # $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
150 localhost.localdomain