SSH
- SSH協(xié)議(Secure Shell,安全外殼)是一種需要進(jìn)行加密和認(rèn)證的,用于遠(yuǎn)程訪問及文件傳輸?shù)木W(wǎng)絡(luò)安全協(xié)議。
SSH基于加密和認(rèn)證的特性可以為用戶提供更強(qiáng)大的安全保障機(jī)制,在用戶使用不安全的網(wǎng)絡(luò)環(huán)境登錄設(shè)備時(shí),SSH能夠有效保護(hù)設(shè)備不受IP地址欺詐、明文密碼截取等攻擊。 - SSH協(xié)議默認(rèn)使用TCP 22號(hào)端口
SFTP
- SFTP(SSH File Transfer Protocol)是一種基于SSH(安全外殼)的安全的文件傳輸協(xié)議,使用SFTP協(xié)議可以在文件傳輸過程中提供一種安全的網(wǎng)絡(luò)的加密算法,從而保證數(shù)據(jù)的安全傳輸。
- SFTP在Linux操作系統(tǒng)中,默認(rèn)的端口客是22,傳輸提供了密碼和密鑰驗(yàn)證機(jī)制,可以有效防止傳輸過程的威脅和公技。
配置SFTP
配置SFTP之前,首先要安裝SSH,即安裝OpenSSH。
安裝OpenSSH
[root@localhost ~]# yum install openssh-server
Last metadata expiration check: 0:11:41 ago on Sun 05 Mar 2023 09:03:07 PM EST.
Package openssh-server-8.0p1-4.el8.x86_64 is already installed.
>>>>>>>>>>>>>> 中間的安裝過程省略 <<<<<<<<<<<<<<
Upgraded:
openssh-8.0p1-13.el8.x86_64 openssh-clients-8.0p1-13.el8.x86_64
openssh-server-8.0p1-13.el8.x86_64
Complete!
[root@localhost ~]#
配置sshd_config配置文件
sshd_config文件一般在目錄 /etc/ssh/ 下面。如下所示
[root@localhost ~]# cd /etc/ssh/
[root@localhost ssh]# ls -n *_config
-rw-r--r--. 1 0 0 1531 3月 16 2023 ssh_config
-rw-------. 1 0 0 3158 10月 23 16:33 sshd_config
[root@localhost ssh]#
打開文件如下:
# the setting of "PermitRootLogin prohibit-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# override default of no subsystems
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp
# Example of overriding settings on a per-user basis
Match User sftptest
X11Forwarding no
AllowTcpForwarding yes
PermitTTY no
ForceCommand internal-sftp
- 注釋掉 Subsystem sftp /usr/libexec/openssh/sftp-server 配置,然后在下一行寫上 Subsystem sftp internal-sftp。注釋行的意思是,需要使用一個(gè)可執(zhí)行的文件sftp-server來(lái)開啟SFTP服務(wù),而新加的行是使用系統(tǒng)自帶的internal-sftp來(lái)開啟SFTP服務(wù)。我們這里使用系統(tǒng)內(nèi)部自帶的。
- 然后Math user 后跟SFTP用戶,即指定那個(gè)用戶可以登陸SFTP服務(wù),多個(gè)時(shí),可以用用戶組的方式,書寫方式Math Group 用戶組。sftptest是我新建的系統(tǒng)用戶。
- AllowTcpForwarding yes的意思是允許長(zhǎng)連接,可默認(rèn),不用修改
- ForceCommand internal-sftp 使用internal-sftp命令
- 其它默認(rèn)就可以了
以上就配置好了SFTP服務(wù)。
重啟SSH服務(wù)
[root@localhost ssh]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service
[root@localhost ssh]#
測(cè)試連接
[root@localhost ssh]# sftp sftptest@127.0.0.1
(sftptest@127.0.0.1) Password:
Connected to 127.0.0.1.
sftp>
這樣就連接上了。
注意,在新建用戶后對(duì)于用戶的根目錄,或是指定的SFTP根目錄執(zhí)行修改權(quán)限的命令 chmod 755 根目錄。有時(shí)這個(gè)也會(huì)引發(fā)無(wú)法登陸的問題。
使用另一個(gè)服務(wù)器上的FileZilla客戶端進(jìn)行連接測(cè)試

filezilla連接成功