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

  3. 参考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

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

  4. 利⽤chkconfig命令查看 telnet状态,并把结果追加到 root主⽬录下的 exam3.txt ⽂件

  5. 把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 
     

    把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 
     
    在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
    2
    3
    4
    在上⼀步的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
    2
    3
    4
    在上⼀步的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窗⼝;
    在新打开的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
     
    登录成功后,切换到/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.00秒 40.00千字节/秒。

     
    修改vsftp的配置⽂件,禁⽌匿名⽤户登录,同时锁定登录⽤户的⽬录,不能进⾏⽬录切换;
    手动搭建FTP站点

    测试匿名⽤户是否可以登录。测试普通⽤户是否可以进⾏⽬录切换;
    C:\Users\lenovo>ftp 192.168.1.1
    连接到 192.168.1.1。
    220 (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.1。
    220 (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.
     
    把C:\Windows\System32\drivers\etc\hosts⽂件copy到桌⾯;
    利⽤lcd 进⾏window⽬录的切换,切换到hosts所在⽬录;
    ftp> lcd C:\Users\lenovo\Desktop
    目前的本地目录 C:\Users\lenovo\Desktop。


    然后把hosts⽂件上传到 a+学号 的⽤户主⽬录中;
    put hosts

    切换到telnet窗⼝,把hosts⽂件的内容追加到 tmp.txt 中;
    [a111@localhost ~]$ sudo cat /var/ftp/test/hosts >> /home/a111/tmp.txt

    把 tmp.txt 重命名为 exam3.txt;
    [root@localhost test]# cd /home/a111/
    [root@localhost a111]# ls
    tmp.txt      systemd services. SysV configuration data might be overridden by native

  6.       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
     [root@localhost a111]# mv tmp.txt exam3.txt




    把 exam3.txt 进⾏ window格式的转换,同时把 unix2dos 的 输出内容追加到 exam3.txt 中;
    [root@localhost ~]# unix2dos /root/exam3.txt 
    unix2dos: converting file /root/exam3.txt to DOS format ...
    #再手动复制粘贴



    把 exam3.txt 通过ftp 传递到window下;
    get exam3.txt

    删除 a+学号 ⽤户信息;
    [root@localhost ~]# userdel -r a111

    把 exam3.txt 重命名为 学号.txt 然后提交;
     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值