就业班 2401--3.11 Linux Day15--ftp数据传输测试server和client+谷歌验证码登录远程连接

文件服务器

路漫漫其修远兮,吾将上下而求索.

构建NFS远程共享存储

一、NFS介绍

文件系统级别共享(是NAS存储) ---------  已经做好了格式化,可以直接用。 速度慢比如:nfs,samba
=====================================================
NFS 
NFS:Network File System 网络文件系统,NFS 和其他文件系统一样,是在 Linux 内核中实现的,因此 NFS 很难做到与 Windows 兼容。NFS 共享出的文件系统会被客户端识别为一个文件系统,客户端可以直接挂载并使用。
​
#NFS 文件系统仅支持基于 IP 的用户访问控制,NFS 的客户端主要为Linux。
因为NFS有很多功能,不同的功能需要使用不同的端口。因此NFS无法固定端口。而RPC会记录NFS端口的信息,这样就能够通过RPC实现服务端和客户端的RPC来沟通端口信息。
​
那RPC和NFS之间又是如何之间相互通讯的?
​
首先当NFS启动后,就会随机的使用一些端口,然后NFS就会向RPC去注册这些端口。RPC就会记录下这些端口。并且RPC会开启111端口,等待客户端RPC的请求,如果客户端有请求,那服务端的RPC就会将记录的NFS端口信息告知客户端。
实验环境准备两台机器
支持多节点同时挂载以及并发写入
服务端:nfs-server 192.168.246.160
客户端:web1 192.168.246.161
centos7(服务端和客户端都关闭防火墙和selinux内核防火墙)
#systemctl stop firewalld
#systemctl disable firewalld    
#setenforce 0

二、实战

NFS-server操作
[root@nfs-server ~]# yum -y install rpcbind  #安装rpc协议的包
[root@nfs-server ~]# yum -y install nfs-utils #安装nfs服务。
启动服务
[root@nfs-server ~]# systemctl start nfs
[root@nfs-server ~]# systemctl start rpcbind
[root@nfs-server ~]# mkdir /nfs-dir   #创建存储目录
[root@nfs-server ~]# echo "nfs-test" >> /nfs-dir/index.html  #制作test文件
[root@nfs-server ~]# vim /etc/exports   #编辑共享文件
/nfs-dir        192.168.246.0/24(rw,no_root_squash,sync)
​
可选参数注释:
ro:只读
rw:读写
*:表示共享给所有网段。
sync:所有数据在请求时写入共享
root_squash: 对于使用分享目录的使用者如果是root用户,那么这个使用者的权限将被压缩成为匿名使用者,只读权限。
no_root_squash:使用分享目录的使用者,如果是 root 的话,那么对于这个分享的目录来说,他就具有 root 的权限。

[root@nfs-server ~]# systemctl restart nfs-server #重启服务。
[root@nfs-server ~]# systemctl enable nfs-server #制作开机启动
web1  客户端操作
[root@web1 ~]# yum -y install rpcbind
[root@web1 ~]# yum -y install nfs-utils
[root@web1 ~]# mkdir /qf #创建挂载点
[root@web1 ~]# mount -t nfs 192.168.246.160:/nfs-dir /qf  #挂载
-t:指定文件系统类型
[root@web1 ~]# df -Th
Filesystem               Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  xfs        17G  1.1G   16G   7% /
tmpfs                    tmpfs      98M     0   98M   0% /run/user/0
192.168.246.160:/nfs-dir nfs4       17G  1.4G   16G   8% /qf
[root@web1 ~]# ls /qf
index.html
[root@web1 ~]# umount /qf  #取消挂载
​
​
制作开机挂载
[root@client.qfedu.com ~]# vim /etc/fstab
192.168.246.160:/nfs-dir    /qf          nfs     defaults        0 0
[root@client.qfedu.com ~]# mount -a

ftp及lftp

  • 文件传输协议(File Transfer Protocol,FTP),基于该协议FTP客户端与服务端可以实现共享文件、上传文件、下载、删除文件。FTP服务器端可以同时提供给多人共享使用。

  • FTP服务是Client/Server(简称C/S)模式,基于FTP协议实现FTP文件对外共享及传输的软件称之为FTP服务器源端,客户端程序基于FTP协议,则称之为FTP客户端,FTP客户端可以向FTP服务器上传、下载文件。

FTP Server
作用:提供文件共享服务,实现上传下载
端口:
21号,建立tcp连接  默认端口
20号:传输数据

一、FTP基础

软件包:        vsftpd
FTP端口:       控制端口:21/tcp 
配置文件:       /etc/vsftpd/vsftpd.conf
1. ftp主动模式
ftp主动模式:客户端开启一个端口N(>1023)向服务端的21端口,建立连接,同时开启一个N+1,告诉服务端,我监听的是N+1端口,服务端接到请求之后,用自己的20端口连接到客户端的N+1端口,进行传输
​
21端口建立连接
20端口传输数据
2. ftp被动模式
ftp被动模式:客户端同时开启两个端口(1024,1025),一个端口(1024)跟服务端的21端口建立连接,并请求,大哥,我连上了,你再开一个端口呗。服务端接到请求之后,随机会开启一个端口(1027)并告诉客户端我开启的是1027端口,客户端用另一个端口(1025)与服务端的(1027)端口进行连接,传输数据

二、Vsftp 服务器简介

  • 非常安全的FTP服务进程(Very Secure FTP daemon,Vsftpd),Vsftpd在Unix/Linux发行版中最主流的FTP服务器程序,优点小巧轻快,安全易用、稳定高效、满足企业跨部门、多用户的使用(1000用户)等。

三、vsftpd配置

1. 安装vsftpd[ftp服务端]
FTP Server(服务端)
实验环境--准备两台机器
关闭防火墙和selinux
#systemctl stop firewalld
#systemctl disable firewalld    
#setenforce 0
=========================================
ftp-server 192.168.246.160
client 192.168.246.161
==========================================
[root@ftp-server ~]# yum install -y vsftpd
[root@ftp-server ~]# systemctl start vsftpd
[root@ftp-server ~]# systemctl enable vsftpd
#FTP默认共享目录:/var/ftp
[root@localhost ~]# mkdir /var/ftp/upload  #创建自己的共享目录
[root@ftp-server ~]# touch /var/ftp/upload/test.txt  #创建文件到共享目录
[root@ftp-server ~]# cd /var/ftp/
[root@ftp-server ftp]# ls
pub upload
[root@ftp-server ftp]# chown ftp.ftp * -R  #修改根目录的属主与属组
[root@ftp-server ftp]# ll 
total 0
drwxr-xr-x. 2 ftp ftp 22 Aug  3 03:15 pub
drwxr-xr-x. 2 ftp ftp 22 Aug 27 03:15 upload
  • 重点:改变根目录的属主,如果不改变的话,只能访问,其他权限不能生效。因为我们是以ftp用户的身份访问的,而默认的属主属组是root。

  • 注意:

- 修改完配置之后需要重启完服务才能生效
- 还需要从新从客户端登陆,否则修改后的配置看不到效果。
2. 编辑配置文件
[root@ftp-server ~]# vi /etc/vsftpd/vsftpd.conf ----找到29行将下面的注释取消
30 anon_umask=022  #添加匿名用户上传下载目录权限掩码
34 anon_other_write_enable=YES

[root@ftp-server ~]# systemctl restart vsftpd
FTP Clinet(客户端)
关闭防火墙和selinux
[root@client ~]# yum -y install lftp #安装客户端
get命令(下载,首先要开启下载功能)
[root@client ~]# lftp 192.168.246.160
lftp 192.168.246.160:~> ls
drwxr-xr-x    2 0        0               6 Oct 30  2018 pub
drwxr-xr-x    2 14       50              6 Oct 30  2018 upload
lftp 192.168.246.160:/> cd upload/
lftp 192.168.246.160:/upload> ls
-rw-r--r--    1 14       50              0 Aug 02 19:14 test.txt
lftp 192.168.246.160:/upload> get test.txt   #下载
lftp 192.168.246.160:/upload> exit
[root@client ~]# ls  #会下载到当前目录
anaconda-ks.cfg  test.txt
​
[root@client ~]# lftp 192.168.246.160
lftp 192.168.246.160:/upload> mkdir dir  #也可以创建目录
mkdir ok, `dir' created
​
put命令(上传命令,上传之前请在服务端进行配置,将上传功能打开)
[root@client ~]# touch a.txt  #创建测试文件
[root@client ~]# mkdir /test/  #创建测试目录
[root@client ~]# touch /test/b.txt #在测试目录下面创建测试文件
[root@client ~]# lftp 192.168.246.160
lftp 192.168.246.160:~> cd upload/
lftp 192.168.246.160:/upload> put /root/a.txt  #上传文件
lftp 192.168.246.160:/upload> ls
-rw-------    1 14       50              0 Nov 16 12:14 a.txt
drwx------    2 14       50              6 Aug 02 19:17 dir
lftp 192.168.246.160:/upload> mirror -R /root/test/  #上传目录以及目录中的子文件
Total: 1 directory, 1 file, 0 symlinks
New: 1 file, 0 symlinks
lftp 192.168.246.160:/upload> ls
drwx------    2 14       50             23 Nov 16 12:18 test
-rw-------    1 14       50              0 Nov 16 12:14 upload.txt
​
lftp 192.168.246.160:/upload> mirror test/  #下载目录
Total: 1 directory, 1 file, 0 symlinks
New: 1 file, 0 symlinks
lftp 192.168.246.160:/upload> exit
[root@cllient ~]# ls
anaconda-ks.cfg  a.txt  test
[root@client ~]# cd test/
[root@client test]# ls
b.txt
3. ftp配置本地用户登录

创建测试用户

创建 zhangsan、lisi  密码都设置为 “123456”

[root@ftp-server ~]# useradd zhangsan 
[root@ftp-server ~]# useradd lisi
[root@ftp-server ~]# echo '123456' | passwd --stdin  zhangsan  #设置密码
Changing password for user zhangsan.
passwd: all authentication tokens updated successfully.
[root@ftp-server ~]# echo '123456' | passwd --stdin  lisi 
Changing password for user lisi.
passwd: all authentication tokens updated successfully.

配置本地用户ftp配置文件

[root@ftp-server ~]# vim /etc/vsftpd/vsftpd.conf  ---添加注释并修改 
anonymous_enable=NO           #将允许匿名登录关闭
#anon_umask=022                #匿名用户所上传文件的权限掩码 
#anon_upload_enable=YES        #允许匿名用户上传文件
#anon_mkdir_write_enable=YES   #允许匿名用户创建目录
#anon_other_write_enable=YES    #是否允许匿名用户有其他写入权(改名,删除,覆盖)
103 chroot_list_enable=YES     #启用限制登陆用户在主目录里面
104 # (default follows)
105 chroot_list_file=/etc/vsftpd/chroot_list  #限制登陆的用户在这个文件列表中,一行一个用户
106 allow_writeable_chroot=YES  #允许限制的用户对目录有写权限
新添加
local_root=/home/zhangsan       # 设置本地用户的FTP根目录,一般为用户的家目录
local_max_rate=0                # 限制最大传输速率(字节/秒)0为无限制

重启vsftpd

[root@ftp-server ~]# vim /etc/vsftpd/chroot_list
zhangsan
[root@ftp-server ~]# systemctl restart vsftpd

四、客户端操作

[root@ftp-client ~]# lftp 192.168.153.137 -u zhangsan
Password: 
lftp zhangsan@192.168.153.137:~> ls
lftp zhangsan@192.168.153.137:~> mkdir aaa
mkdir ok, `aaa' created
lftp zhangsan@192.168.153.137:~> ls
drwxr-xr-x    2 1000     1000            6 Aug 02 20:55 aaa
lftp zhangsan@192.168.153.137:~> put /root/test.txt 
lftp zhangsan@192.168.153.137:~> ls
drwxr-xr-x    2 1000     1000            6 Aug 02 20:55 aaa
-rw-r--r--    1 1000     1000            0 Aug 02 20:59 test.txt
​
服务器端查看
[root@ftp-server ~]# cd /home/zhangsan/
[root@ftp-server zhangsan]# ls
aaa  test.txt
[root@ftp-server zhangsan]# ll
total 0
drwxr-xr-x. 2 zhangsan zhangsan 6 Aug  3 04:55 aaa
-rw-r--r--. 1 zhangsan zhangsan 0 Aug  3 04:59 test.txt

Linux禁止root用户远程登陆

认识sshd_congfig配置文件
[root@testpm ~]# vim /etc/ssh/sshd_config
​
#Port 22  #监听端口,默认监听22端口   【默认可修改】
#AddressFamily any  #IPV4和IPV6协议家族用哪个,any表示二者均有
#ListenAddress 0.0.0.0 #指明监控的地址,0.0.0.0表示本机的所有地址  【默认可修改】
#ListenAddress ::  #指明监听的IPV6的所有地址格式
​
#LogLevel INFO    #日志记录级别,默认为info
#LoginGraceTime 2m   #登录的宽限时间,默认2分钟没有输入密码,则自动断开连接
#PermitRootLogin yes #是否允许管理员直接登录,'yes'表示允许,实际生产中建议修改为no
#MaxAuthTries 6  #最大认证尝试次数,最多可以尝试6次输入密码超过之后断开连接
#MaxSessions 10  #最大允许保持多少个连接。默认值是 10
​
#PubkeyAuthentication yes  #是否开启公钥验证
禁止root用户远程登录
[root@testpm ~]# vim /etc/ssh/sshd_config
37 #LoginGraceTime 2m
38 #PermitRootLogin yes  #默认为允许root用户远程登陆
39 #StrictModes yes
进行修改如下
[root@testpm ~]# vim /etc/ssh/sshd_config
37 #LoginGraceTime 2m
38 PermitRootLogin no #将注释打开并将yes修改为no
39 #StrictModes yes
保存退出并重启sshd服务
[root@testpm ~]# systemctl restart sshd

谷歌验证登录

配置本地yum源

[root@localhost ~]# yum install -y git automake libtool pam-devel bzip2 wget vim ntpdate
校对时间(时间一定要对,不然会出大问题)
#修改时区
[root@localhost ~]# timedatectl set-timezone Asia/Shanghai
#校对时间
[root@localhost ~]# ntpdate time.windows.com

下载工具包

[root@localhost ~]# wget http://repository.timesys.com/buildsources/l/libpam-google-authenticator/libpam-google-authenticator-1.0/libpam-google-authenticator-1.0-source.tar.bz2

解压

[root@localhost ~]# tar -xjvf libpam-google-authenticator-1.0-source.tar.bz2

编译安装

[root@localhost ~]# cd libpam-google-authenticator-1.0
[root@localhost ~]# make && make install

修改ssh服务的配置

[root@localhost ~]# echo "auth required pam_google_authenticator.so" >> /etc/pam.d/sshd
#修改sshd配置文件
[root@localhost ~]# vim /etc/ssh/sshd_config
这个是文件自己有的不需要自己添加
    ChallengeResponseAuthentication yes
#重启sshd服务
[root@localhost ~]# systemctl restart sshd

使用令牌工具生成登录密钥

[root@localhost ~]# google-authenticator
google-authenticator 
​
Do you want authentication tokens to be time-based (y/n) y
https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@localhost.localdomain%3Fsecret%3DWLJCY4JSNGQNH454                                                                           
Your new secret key is: WLJCY4JSNGQNH454
Your verification code is 635811
Your emergency scratch codes are:
  18263912
  56060832
  39571822
  20569639
  90543013
​
Do you want me to update your "/root/.google_authenticator" file (y/n) y
​
Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y
​
By default, tokens are good for 30 seconds and in order to compensate for
possible time-skew between the client and the server, we allow an extra
token before and after the current time. If you experience problems with poor
time synchronization, you can increase the window from its default
size of 1:30min to about 4min. Do you want to do so (y/n) y
​
If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting (y/n) n

使用动态码登录服务器(WindTerm不行,finalshell可以)

然后重新登陆即可,需要下载一个谷歌验证器(app),就有验证码!!!!!

补充

(ftp和http)区别

FTP(File Transfer Protocol,文件传输协议)和HTTP(Hypertext Transfer Protocol,超文本传输协议)是两种在计算机网络中常用的协议,它们的主要区别体现在以下几个方面:

  1. 定义和用途:FTP主要被用于文件传输,特别是在两台计算机之间互相传送文件。无论是上传文件还是下载文件,FTP都是非常适用的协议。而HTTP则主要是为网页浏览设计的,它用于从服务器读取Web页面内容,使得用户可以通过浏览器浏览和交互网页。
  2. 运作方式:FTP使用两个TCP连接,一个是命令链路,用于在FTP客户端与服务器之间传递命令;另一个是数据链路,用于上传或下载数据。而HTTP协议则是基于请求/响应范式的,通常是在用户代理和源服务器之间通过一个单独的连接来完成。
  3. 时效性和连接方式:FTP具有较高的延时,并且可能需要执行冗长的登录进程。相比之下,HTTP的连接是实时的,即使存在延时,也是非常细微的差距。
  4. 安全性:FTP在传输文件时并不提供加密功能,因此传输的数据可能会被第三方截获。而HTTP虽然本身也不提供加密,但可以通过HTTPS(HTTP Secure)协议实现加密传输,确保数据的安全性。
  5. 控制信息的传送方式:FTP的控制信息是带外(out-of-band)传送的,即控制信息和数据信息的传输是分开的。而HTTP的控制信息是带内(in-band)传送的,即在同一个TCP连接中既发送请求和响应首部行,也传输实际的数据。
  6. 状态管理:FTP服务器在整个会话期间需要保留用户的状态信息,而HTTP是无状态的,每个请求都是独立的。

综上所述,FTP和HTTP各有其特点和适用场景,用户应根据具体需求选择适当的协议。FTP适用于大量数据的传输和文件管理,而HTTP则更适合用于浏览和交互式的Web应用。

 

绿色的还是关闭的,大概率是个工具,是正常的!

showmount -e 1912.42.45.11

看有没有可以挂载的nfs

showmount -a 刷新配置

放到后台,跳过这个选项,确保客户端正常运行。

  • 27
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值