Linux 实验三

  1. 利⽤SSH客户端远程登录root⽤户;

  2. 参考ppt内容,安装并启动telnet服务(xinetd模式);

[root@localhost ~]# yum install -y xinetd
[root@localhost ~]# yum install -y telnet
[root@localhost ~]# yum install -y telnet-server
[root@localhost ~]# vim /etc/xinetd.d/telnet	# 下方内容复制到/etc/xinetd.d/telnet

service telnet
{ 
        flags = REUSE
        socket_type = stream
        wait = no
        user = root
        server =/usr/sbin/in.telnetd
        log_on_failure += USERID
        disable = no		# 负负得正。所以 disable= no 表示启用用这个服务
}

# 开启xinetd服务
[root@localhost ~]# service xinetd restart
Redirecting to /bin/systemctl restart xinetd.service

# 查看telnet客户端是否开启成功
[root@localhost ~]# telnet 127.0.0.1
Trying 127.0.0.1...
Connected to 127.0.0.1.

安装xinetd

  1. 参考ppt内容,安装并启动ftp服务(stand alone模式);
yum install -y vsftpd ftp

#配置文件
vi /etc/vsftpd/vsftpd.conf

#对照一遍配置文件,配置文件如下
anonymous_enable=YES #允许匿名登录
local_enable=YES #允许本地用户登录
write_enable=YES #开放本地用户的写权限
local_umask=022 #指定目录和文件被创建时得到的初始权限
dirmessage_enable=YES #当切换目录时,显示该目录的信息。
xferlog_enable=YES #记录ftp上传下载的日志记录
connect_from_port_20=YES #指定是否支持PORT模式
xferlog_std_format=YES #传输日志文件将以标准xferlog格式写入
listen=NO #是否使用IPV4的stand-alone模式
listen_ipv6=YES #是否使用IPV6的stand-alone模式,与listen互斥
pam_service_name=vsftpd #指定vsftpd将使用的PAM服务的名称
userlist_enable=YES #从userlist_file给出的文件名加载用户名列表

userlist_enable
用法:YES/NO 默认为YES,若是启动此功能,则会读/etc/vsftpd.user_list 当中的使用者名称,只有出现在文件中的用户名才能登录ftp
此项功能可以在询问密码前就出现失败讯息,而不需要检验密码的程序

userlist_deny
用法:YES/NO  默认为NO,这个选项只有在userlist_enable 启动时才会被检验,如果将这个选项设为YES,则在/etc/vsftpd.user_list 中的使用者将无法登入; 若设为NO , 则只有在/etc/vsftpd.user_list 中的使用者才能登入。
此项功能可以在询问密码前就出现错误讯息,而不需要检验密码的程序

#启动vsftpd
service vsftpd start

#若不成功,显示报错如下:
[root@localhost vsftpd]# service vsftpd start
Redirecting to /bin/systemctl start vsftpd.service
Job for vsftpd.service failed because the control process exited with error code. See "systemctl status vsftpd.service" and "journalctl -xe" for details.
[root@localhost vsftpd]# systemctl status vsftpd.service
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2022-04-11 10:42:37 CST; 13s ago
  Process: 9648 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=1/FAILURE)

Apr 11 10:42:34 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
Apr 11 10:42:37 localhost.localdomain systemd[1]: vsftpd.service: control process exited, code=exited status=1
Apr 11 10:42:37 localhost.localdomain systemd[1]: Failed to start Vsftpd ftp daemon.
Apr 11 10:42:37 localhost.localdomain systemd[1]: Unit vsftpd.service entered failed state.
Apr 11 10:42:37 localhost.localdomain systemd[1]: vsftpd.service failed.

#则查看进程
[root@localhost ~]# netstat -natp | grep 21
tcp6       0      0 :::21                   :::*                   	LISTEN      9518/xinetd 

#进程显示刚刚启动的xinetd占用了21端口,而vsftpd也是用21端口,那么关闭xinetd
[root@localhost ~]# service xinetd stop
[root@localhost ~]# netstat -natp | grep 21
[root@localhost ~]# service vsftpd start#成功启动后无显示
#重新启动xinetd,为后面的实验做准备
[root@localhost ~]# service xinetd start

  1. 创建名为 a+学号 的账号,并在sudoers⽂件中添加该⽤户信息,使得该⽤户可以使⽤sudo命令;
[root@localhost ~]# useradd a111
[root@localhost ~]# passwd a111 #设置用户密码,一定要设置,不然会在后面telnet登录出错

给用户赋权限

  1. 利⽤chkconfig命令查看 telnet状态,并把结果追加到 root主⽬录下的 exam3.txt ⽂件中;
[root@localhost ~]# chkconfig --list | grep telnet

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

	telnet:        	on
[root@localhost ~]#chkconfig --list | grep telnet >> /root/exam3.txt
  1. 把vsftpd的进程信息追加到 exam3.txt ⽂件中(注意去掉grep本身那⼀条记录);
[root@localhost ~]# ps -ef | grep vsftpd | grep -v "grep"
root      9676     1  0 10:45 ?        00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
[root@localhost ~]# ps -ef | grep vsftpd | grep -v "grep" >> exam3.txt 
  1. 把telnet的配置⽂件的内容追加到 exam3.txt 中;
[root@localhost ~]# cat /etc/xinetd.d/telnet
service telnet
{ 
        flags = REUSE
        socket_type = stream
        wait = no
        user = root
        server =/usr/sbin/in.telnetd
        log_on_failure += USERID
        disable = no
}
[root@localhost ~]# cat /etc/xinetd.d/telnet >> exam3.txt 
  1. 在window命令⾏下,使⽤ a+学号 帐号 telnet 登录linux,把root主⽬录下的 exam3.txt ⽂件复制到当前⽤户的主⽬录下 tmp.txt ,并把 tmp.txt 的所属⽤户和所属组改为当前⽤户和当前⽤户所属的组;
C:\Users\lenovo>telnet 192.168.1.1
[a111@localhost ~]$ sudo cp /root/exam3.txt /home/a111/tmp.txt
[a111@localhost ~]$ sudo chown a111 /home/a111/tmp.txt
[a111@localhost ~]$ sudo chgrp a1113 /home/a111/tmp.txt
  1. 在上⼀步的telnet登录中,把当前路径和当前时间追加到 tmp.txt 中;
[a111@localhost ~]$ sudo pwd
/home/a111
[a111@localhost ~]$ sudo pwd >> /home/a111/tmp.txt
[a111@localhost ~]$ date '+%Y-%m-%d %H:%M:%S' >> /home/a111/tmp.txt
  1. 在上⼀步的telnet登录中,把/etc/passwd⽂件中的第1、3、4字段内容(⽤户名、uid和gid信息)追加到 tmp.txt 中;
[a111@localhost ~]$ sudo cat /etc/passwd | awk -F: '{print $1,$3,$4}' >> /home/a111/tmp.txt
  1. 保留当前telent窗⼝,重新打开⼀个cmd窗⼝;
  2. 在新打开的cmd窗⼝中使⽤ftp命令进⾏匿名登录(⽤户名:ftp,密码为:空);
C:\Users\lenovo>ftp 192.168.1.1  #(⽤户名:ftp,密码为:空)
  1. 退出ftp⽤户登录,并登录 a+学号 ⽤户;
    注意,如果提示425 Failed to establish connection. 请关闭windows防⽕墙
ftp> close
221 Goodbye.
ftp> quit
C:\Users\dell>ftp 192.168.1.1
  1. 登录成功后,切换到/usr⽬录,并查看⽬录内容。发现⽤户可以访问其他⽬录;
ftp> cd /usr
250 Directory successfully changed.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
bin
etc
games
include
lib
lib64
libexec
local
sbin
share
src
tmp
226 Directory send OK.
ftp: 收到 80 字节,用时 0.0040.00千字节/秒。
  1. 修改vsftp的配置⽂件,禁⽌匿名⽤户登录,同时锁定登录⽤户的⽬录,不能进⾏⽬录切换;

手动搭建FTP站点

  1. 测试匿名⽤户是否可以登录。测试普通⽤户是否可以进⾏⽬录切换;
C:\Users\lenovo>ftp 192.168.1.1
连接到 192.168.1.1220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.1.1:(none)): ftp
331 Please specify the password.
密码:
530 Login incorrect.
登录失败。
#普通用户不可以进行目录切换
C:\Users\lenovo>ftp 192.168.1.1
连接到 192.168.1.1220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.1.1:(none)): a111
331 Please specify the password.
密码:
230 Login successful.
ftp> cd /usr
550 Failed to change directory.
  1. 把C:\Windows\System32\drivers\etc\hosts⽂件copy到桌⾯;
  2. 利⽤lcd 进⾏window⽬录的切换,切换到hosts所在⽬录;
ftp> lcd C:\Users\lenovo\Desktop
目前的本地目录 C:\Users\lenovo\Desktop。
  1. 然后把hosts⽂件上传到 a+学号 的⽤户主⽬录中;
put hosts
  1. 切换到telnet窗⼝,把hosts⽂件的内容追加到 tmp.txt 中;
[a111@localhost ~]$ sudo cat /var/ftp/test/hosts >> /home/a111/tmp.txt
  1. 把 tmp.txt 重命名为 exam3.txt;
[root@localhost test]# cd /home/a111/
[root@localhost a111]# ls
tmp.txt
[root@localhost a111]# mv tmp.txt exam3.txt
  1. 把 exam3.txt 进⾏ window格式的转换,同时把 unix2dos 的 输出内容追加到 exam3.txt 中;
[root@localhost ~]# unix2dos /root/exam3.txt 
unix2dos: converting file /root/exam3.txt to DOS format ...
#再手动复制粘贴
  1. 把 exam3.txt 通过ftp 传递到window下;
get exam3.txt
  1. 删除 a+学号 ⽤户信息;
[root@localhost ~]# userdel -r a111
  1. 把 exam3.txt 重命名为 学号.txt 然后提交;
一、 实验目的 1、通过实验了解和熟悉Linux系统管理; 2、掌握用户和组管理命令; 3、掌握软件包安装命令和步骤; 4、掌握网络通信管理命令; 5、掌握进程管理命令; 6、掌握系统的服务管理命令; 7、掌握磁盘操作管理命令。 二、 开发工具和运行环境 1、虚拟机VMware 2、Linux操作系统 、 实验内容 1、了解和熟悉Linux系统管理 2、用户和组管理命令 (1)帐户管理命令: useradd、 usermod、 passwd、userdel (2)组帐户管理命令: groupadd、 groupdel. gpasswd 3、软件包安装命令和步骤 (1) RPM 包的安装 安装RPM包的基本命令格式是: rpm -ivh (2) RPM 包的删除 删除RPM包的基本命令格式是: rpm -e (3) RPM 包的查询 rpm - qa (4) RPM 包的升级 升级RPM包的基本命令格式是: rpm -Uvh (5) RPM包的验证 验证RPM包的基本命令格式是: rpm -V [参数] (6)建立TAR包 有两种方式: -种是建立普通的TAR包,只打包,不压缩 tar cvf 另一种是打包并压缩,选项是“zcvf”,其中“z”代表使用“gzip” 程序 进行文件的压缩 tar zcvf (7)查询TAR包 在释放TAR包之前,查看TAR包中的文件内容。其格式如下: tar ztf (8)释放TAR包 它也分为解非压缩和压缩包两种方式,命令格式如下: tar zxvf 4、网络通信管理命令 (1)hostname命令:显示及设置主机名。 (2)ifconfig命令:显示当前活动的(或指定的)网卡设置。 其格式为: ifconfig [网卡设备名] 重新设置网卡的IP地址,-般由root用户进行设置。其格式为: Ifconfig 网卡设备名 IP 地址 (3) ping命令:网络测试命令 ping [-c报文数] 目的主机地址 (4)write命令:实时给其他用户发送消息 write username [tty] (5)wall命令:以广播方式向系统中的所有用户发送消息 wall message (6)mail 命令:双方用户不同时在线时,使用mai发送和接收消息 mail username mail -s topic username<filename 查看邮件使用mail命令,输入邮件编号以查看邮件 5、进程管理命令 (1)at命令:定时任务命令 (2)ps命令:进程查看命令 ps -ef ps -axu (3)free命令:显示系统内存的使用情况,包括内存总量、已经使用内存数量,空闲内存数量等信息。 (4) top命令:实时监控系统进程。 (5)sleep 命令:用于使进程延迟一段时间再执行。 其格式为: sleep time; command (6)kill命令:来杀死程序产生的进程来结束程序的运行。 格式1 : kill PID 格式2 : kill -9 PID “-9”为SIGKILL信号,属于强制结束 (7)前台与后台运行相关命令 command、command & 6、系统的服务管理命令 (1) runlevel 命令:显示系统当前和上一次的运行级别 (2) init 命令:转换服务的运行级别 init n (3)systemctl 命令:系统服务管理 查看系统服务启动状态。其格式: systemctl list-unit-files --type service 列出所有处于激活状态的服务。其格式为: systemctl list-units --type service --all 服务状态控制。其格式: systemctl [status/start/stop/ restart/reload] name.service 服务开机自启控制。其格式: systemctl [enable/di sable] name.service 7、磁盘操作管理命令 (1)查看系统磁盘分区情况命令: Fdisk -l (2)使用命令手工挂载 mount命令:查看所有挂载设备 mount [-t fs-type] [-o option] device mountpoint 例: mount /dev/cdrom /mnt/cdrom (注意,先要建立挂载目录,并保证设备存在) (3)卸载 umount [device] [dir]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值