chapter02 - 03 作业

 

1、分别用cat \tac\nl三个命令查看文件/etc/ssh/sshd_config文件中的内容,并用自己的话总计出这三个文档操作命令的不同之处?

[root@localhost ~]# cat /etc/ssh/sshd_config //正序显示文件内容

# $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $ //

# This is the sshd server system-wide configuration file.  See

# sshd_config(5) for more information.

 

[root@localhost ~]# tac /etc/ssh/sshd_config   //倒叙显示文件内容

ssh_config                ssh_host_ecdsa_key        ssh_host_ed25519_key      ssh_host_rsa_key

sshd_config               ssh_host_ecdsa_key.pub    ssh_host_ed25519_key.pub  ssh_host_rsa_key.pub

[root@localhost ~]# tac /etc/ssh/sshd_config

 

 

[root@localhost ~]# nl /etc/ssh/sshd_config   //nl可以显示行号,

     1 # $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $  

       

     2 # This is the sshd server system-wide configuration file.  See

     3 # sshd_config(5) for more information.

2、分别用moreless查看/etc/ssh/sshd_config里面的内容,请用总结moreless两个命令的相同和不同之处?

[root@localhost ~]# more /etc/ssh/sshd_config ////全屏分页,按空格键可以向下查看

# $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $

 

# This is the sshd server system-wide configuration file.  See

# sshd_config(5) for more information.

[root@localhost ~]#  less /etc/ssh/sshd_config //全屏分页,可以查找内容

 

 

 

 

#       $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $

 

3、将/etc/passwd文件中的前20行重定向保存到/root下改名为20_pass.txt,/etc/passwd文件中的后15行重定向保存到/root下改名为:pass_15.txt

[root@localhost ~]# head -20 /etc/passwd > /root/20.pass.txt

[root@localhost ~]# ls /root

20.pass.txt      pass  test      xxy.gz   公共  视频  文档  音乐

anaconda-ks.cfg  qwer  test.txt  xxy.zip  模板  图片  下载  桌面

 

[root@localhost ~]# tail -15 /etc/passwd > /root/pass_15.txt

[root@localhost ~]# ls /root

20.pass.txt      pass         qwer  test.txt  xxy.zip  模板  图片  下载  桌面

anaconda-ks.cfg  pass_15.txt  test  xxy.gz    公共     视频  文档  音乐

[root@localhost ~]#

4、请用一个命令统计/etc/hosts文件包含有多少行?多少字节?多少单词数?

[root@localhost ~]# wc -lwc /etc/hosts

  2  10 158 /etc/hosts

5、练习使用grepegrep

5.1.通过grep管道工具过滤出ifconfig命令显示信息中的IP字段?

[root@localhost ~]# ifconfig | grep "inet"

        inet 192.168.100.143  netmask 255.255.255.0  broadcast 192.168.100.255

        inet6 fe80::20c:29ff:fe33:ffd2  prefixlen 64  scopeid 0x20<link>

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

5.2./etc/passwd文件中的前20行重定向保存到/root下名称为pass

[root@localhost ~]# head -20 /etc/passwd > /root/pass

[root@localhost ~]# ls /root

20.pass.txt      pass         qwer  test.txt  xxy.zip  模板  图片  下载  桌面

anaconda-ks.cfg  pass_15.txt  test  xxy.gz    公共     视频  文档  音乐

5.3.过滤/etc/passwd文件中含有/sbin/nologin 的行并统计行数?

[root@localhost ~]# grep "/sbin/nologin" |wc -l /etc/passwd
40 /etc/passwd

5.4 过滤/etc/passwd文件中以sh结尾的行,及以 root开头的行,不显示包含login的行?

[root@localhost ~]# grep "^root" /etc/passwd |grep "sh$"|grep -v "login"

root:x:0:0:root:/root:/bin/bash

5.5 分别用grepegrep过滤出/etc/ssh/sshd_config文件中不包含“#”开头和空白的行?

[root@localhost ~]# grep -v "^#" /etc/ssh/sshd_config |grep -v "^$"

HostKey /etc/ssh/ssh_host_rsa_key

HostKey /etc/ssh/ssh_host_ecdsa_key

HostKey /etc/ssh/ssh_host_ed25519_key

SyslogFacility AUTHPRIV

AuthorizedKeysFile .ssh/authorized_keys

PasswordAuthentication yes

ChallengeResponseAuthentication no

GSSAPIAuthentication yes

GSSAPICleanupCredentials no

6.1 通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.gz

[root@localhost ~]# tar cjvf /root/file.tar.gz /etc/passwd

tar: 从成员名中删除开头的“/

/etc/passwd

[root@localhost ~]# ls /root

20.pass.txt      file.tar.gz  pass_15.txt  test      xxy.gz   公共  视频  文档  音乐

anaconda-ks.cfg  pass         qwer         test.txt  xxy.zip  模板  图片  下载  桌面

 

6.2通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.bz2

[root@localhost ~]# tar cjvf /root/file.tar.bz2 /etc/passwd

tar: 从成员名中删除开头的“/

/etc/passwd

[root@localhost ~]# ls /root

20.pass.txt      file.tar.bz2  pass         qwer  test.txt  xxy.zip  模板  图片  下载  桌面

anaconda-ks.cfg  file.tar.gz   pass_15.txt  test  xxy.gz    公共     视频  文档  音乐

6.3创建空文件夹/web/test1,并将file.tar.bz2 解包并释放到/web/test1目录下?

[root@localhost web]# tar xf /root/file.tar.bz2 -C /web/test1

[root@localhost web]# ls /web/test1

etc

7.1 通过vi编辑/web/test1/passwd文件将文件里为root单词全部替换成benet

[root@localhost ~]# vi /web/test1/etc/passwd

 

benet:x:0:0:benet:/benet:/bin/bash

7.2 通过vi编辑 删除pass文件第1510行。

[root@localhost ~]# vi pass

:set nu

1 line less; before #1  91 seconds ago

2 more lines; before #2  3 seconds ago

7.3 vi中显示pass文件行号复制文件2 3 4行粘贴到以lp开头的行下。

[root@localhost ~]# vi pass

:set nu

Already at oldest change

7.4 通过vi编辑 查找文件内包含mail var等字符串,并记录所在行号。

[root@localhost ~]# vi /root/pass

 10 mail:x:8:12:mail:/var/spool/mail:/sbin/nologi

7.5 通过vi编辑 快速跳转到文件的第二行,通过r 读取 /etc/hosts 文件的内容到第二行下。

[root@localhost ~]# vi /root/pass

输入2G跳转

"/etc/hosts" 2L, 158C

7.6将更改后的文件使用vim另存为/root/new_pass

w /root/new_pass

[root@localhost ~]# ls /root

20.pass.txt      file.tar.bz2  new_pass  pass_15.txt  test      xxy.gz   公共  视频  文档  音乐

anaconda-ks.cfg  file.tar.gz   pass      qwer         test.txt  xxy.zip  模板  图片  下载  桌面

7.7new_pass文件压缩成gz格式并改名为npass.gz文件。

[root@localhost ~]# mv /root/new_pass.gz /root/npass.gz

[root@localhost ~]# ls root

ls: 无法访问root: 没有那个文件或目录

[root@localhost ~]# ls /root

20.pass.txt      file.tar.bz2  npass.gz  pass_15.txt  test      xxy.gz   公共  视频  文档  音乐

anaconda-ks.cfg  file.tar.gz   pass      qwer         test.txt  xxy.zip  模板  图片  下载  桌面

8统计/dev 目录下的文件数量。

[root@localhost ~]# ls -l /dev/ | wc -l

155

9.1/boot下查找文件名以vmlinuz开头的文件?

[root@localhost ~]# find /boot -name "vmlinuz*"

/boot/vmlinuz-3.10.0-229.el7.x86_64

/boot/vmlinuz-0-rescue-763c44ac9097424ab7f8faff2fe6db2e

9.2/boot下查找文件大小大于3M 小于 20M 的文件

[root@localhost ~]# find /boot -size +3M -size +20M

/boot/vmlinuz-3.10.0-229.el7.x86_64

/boot/vmlinuz-0-rescue-763c44ac9097424ab7f8faff2fe6db2e

/boot/initramfs-3.10.0-229.el7.x86_64.img

10 请详细写出构建本地yum仓库的步骤?并在每行命令后面用自己的话做上中文注释?

[root@localhost ~]# umount /dev/sr0 //把前面安装的卸载

[root@localhost ~]# mount /dev/sr0 /media/ //把光盘挂载上个

mount: /dev/sr0 写保护,将以只读方式挂载

[root@localhost ~]# ls /media/   //查询是否挂载

 

[root@localhost ~]# cd /etc/yum.r*

[root@localhost yum.repos.d]# mkdir a/   //构建本地yum仓库

root@localhost yum.repos.d]# mv C* a/

 

[cdrom]

name=cdrom         //仓库名字

baseurl=file:///media        //指定rpm包的位置

enabled=1       //启用本地yum仓库

gpgcheck=0   //禁用gpg效验

 

[root@localhost yum.repos.d]# yum -y clean all   //清除yum缓存

已加载插件:fastestmirror, langpacks

正在清理软件源: cdrom

Cleaning up everything

Cleaning up list of fastest mirrors

[root@localhost yum.repos.d]# yum makecache    //重新建立yum缓存

已加载插件:fastestmirror, langpacks

cdrom                                                                             | 3.6 kB  00:00:00     

(1/4): cdrom/group_gz                                                             | 154 kB  00:00:00     

(2/4): cdrom/primary_db                                                           | 2.7 MB  00:00:00     

(3/4): cdrom/other_db                                                             | 1.1 MB  00:00:00     

(4/4): cdrom/filelists_db                                                         | 2.7 MB  00:00:00     

Determining fastest mirrors

元数据缓存已建立

 

[root@localhost yum.repos.d]# rpm -q vsftpd    //查询是否安装

未安装软件包 vsftpd

[root@localhost yum.repos.d]# yum makecache  //安装

已加载插件:fastestmirror, langpacks      //查询是否安装

已安装:

  vsftpd.x86_64 0:3.0.2-9.el7                                                                            

 

完毕!

 rpm -p vsftpd

RPM 版本 4.11.1

版权所有 (C) 1998-2002 - 红帽公司。

该程序可以在 GNU GPL 条款下自由分发

 

11、用yum命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

[root@localhost yum.repos.d]# yum -y install vsftpd    //查询是否安装

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

软件包 vsftpd-3.0.2-9.el7.x86_64 已安装并且是最新版本

无须任何处理

 

[root@localhost yum.repos.d]# yum -y remove vsftpd    //删除安装

已加载插件:fastestmirror, langpacks

正在解决依赖关系

--> 正在检查事务

---> 软件包 vsftpd.x86_64.0.3.0.2-9.el7 将被 删除

--> 解决依赖关系完成

12、用rpm命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

[root@localhost yum.repos.d]# rpm -q vsftpd   //rpm查询是否安装

未安装软件包 vsftpd

[root@localhost Packages]# rpm -iv vsftpd-3.0.2-9.el7.x86_64.rpm  //rpm安装

警告:vsftpd-3.0.2-9.el7.x86_64.rpm: V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY

软件包准备中...

vsftpd-3.0.2-9.el7.x86_64

[root@localhost Packages]# rpm -q vsftpd   //查询是否安装

vsftpd-3.0.2-9.el7.x86_64

[root@localhost Packages]# rpm -e vsftpd-3.0.2-9.el7.x86_64   //卸载包

[root@localhost Packages]# rpm -q vsftpd

未安装软件包 vsftpd

13、通过源码方式通过解包、配置、编译、安装四个步骤安装源码软件httpd-2.2.17.tar.gz?并进行测试?

[root@localhost ~]# ls

20.pass.txt      file.tar.gz          pass         test      xxy.zip  视频  下载

anaconda-ks.cfg  httpd-2.2.17.tar.gz  pass_15.txt  test.txt  公共     图片  音乐

file.tar.bz2     npass.gz             qwer         xxy.gz    模板     文档  桌面

[root@localhost ~]#

[root@localhost ~]# tar -xf httpd-2.2.17.tar.gz -C /usr/src

[root@localhost ~]# ls

20.pass.txt      file.tar.gz          pass         test      xxy.zip  视频  下载

anaconda-ks.cfg  httpd-2.2.17.tar.gz  pass_15.txt  test.txt  公共     图片  音乐

file.tar.bz2     npass.gz             qwer         xxy.gz    模板     文档  桌面

[root@localhost ~]# tar -xf httpd-2.2.17.tar.gz -C /usr/src/

[root@localhost ~]# ls

20.pass.txt      file.tar.gz          pass         test      xxy.zip  视频  下载

anaconda-ks.cfg  httpd-2.2.17.tar.gz  pass_15.txt  test.txt  公共     图片  音乐

file.tar.bz2     npass.gz             qwer         xxy.gz    模板     文档  桌面

[root@localhost ~]# cd /usr/src/httpd-2.2.17/

[root@localhost httpd-2.2.17]# ls

ABOUT_APACHE  buildconf      emacs-style     LAYOUT        NOTICE            ROADMAP

acinclude.m4  CHANGES        httpd.dsp       libhttpd.dsp  NWGNUmakefile     server

Apache.dsw    config.layout  httpd.spec      LICENSE       os                srclib

build         configure      include         Makefile.in   README            support

BuildAll.dsp  configure.in   INSTALL         Makefile.win  README.platforms  test

BuildBin.dsp  docs           InstallBin.dsp  modules       README-win32.txt  VERSIONING

 

yum -y install gcc gcc-c++

[root@localhost httpd-2.2.17]# tar -xf httpd-2.2.17.tar.gz -C /usr/src/

 cd /usr/src/httpd-2.2.17/

root@localhost httpd-2.2.17]# ./configure --prefix=/usr/local/apache

[root@localhost httpd-2.2.17]# make

[root@localhost httpd-2.2.17]# make install