分離)
目錄一、增加sftp的deamon二、增加sftp的service三、其他配套文件四、修改配置文件五、分別重啟兩個(gè)服務(wù)由于安全需要客戶(hù)這邊想把sftp使用的端口與ssh使用的端口分開(kāi)。我們知道sftp沒(méi)有自己的服務(wù)器守護(hù)進(jìn)程它需要依賴(lài)sshd守護(hù)進(jìn)程來(lái)完成客戶(hù)端的連接操作。sftp服務(wù)作為ssh的一個(gè)子服務(wù)是通過(guò) /etc/ssh/sshd_config 配置文件中的Subsystem實(shí)現(xiàn)的如果沒(méi)有配置Subsystem參數(shù)則系統(tǒng)是不能進(jìn)行sftp訪(fǎng)問(wèn)的。所以要分離ssh和sftp服務(wù)的話(huà)基本的思路是創(chuàng)建兩個(gè)sshd進(jìn)程分別監(jiān)聽(tīng)在不同的端口一個(gè)作為ssh服務(wù)的deamon另一個(gè)作為sftp服務(wù)的deamon。分離步驟如下一、增加sftp的deamon為了方便我們將sftp服務(wù)的后臺(tái)程序命名為/usr/sbin/sftpd。/usr/sbin/sftpd做一個(gè)連接指向/usr/sbin/sshd。cp-a/usr/sbin/sshd/usr/sbin/sftpd二、增加sftp的service實(shí)現(xiàn)sftp服務(wù)時(shí)將/usr/lib/systemd/system/sshd.service 復(fù)制到 /etc/systemd/system/sftpd.service然后修改sftpd.service文件內(nèi)容。cp-a/usr/lib/systemd/system/sshd.service/etc/systemd/system/sftpd.service[roottongweb RMANTEST]# vi /etc/systemd/system/sftpd.service[Unit]DescriptionSftpd server daemon#(這行需要修改)Documentationman:sshd(8)man:sshd_config(5)Afternetwork.target sshd-keygen.service Wantssshd-keygen.service[Service]Typenotify EnvironmentFile/etc/sysconfig/sftpd#(這行需要修改)ExecStart/usr/sbin/sftpd-f/etc/ssh/sftpd_config#(這行需要修改)ExecReload/bin/kill-HUP$MAINPIDKillModeprocessRestarton-failure RestartSec42s[Install]WantedBymulti-user.targetsystemctl enable sftpd.service如果openssh采用二進(jìn)制包升級(jí)過(guò)比如從OS自帶的7.4p1版本升級(jí)到8.6p1版本sftpd.service文件中需要做下面的修改[Service]Typesimple三、其他配套文件復(fù)制/etc/pam.d/目錄下的sshd文件放到同目錄命名為sftpdcp-a/etc/pam.d/sshd/etc/pam.d/sftpd復(fù)制/etc/ssh/目錄下的sshd_config文件放到同目錄命名為sftpd_configcp-a/etc/ssh/sshd_config/etc/ssh/sftpd_config復(fù)制/etc/sysconfig/目錄下的sshd文件放到同目錄命名為sftpdcp-a/etc/sysconfig/sshd/etc/sysconfig/sftpd創(chuàng)建sftp服務(wù)運(yùn)行pid文件touch/var/run/sftpd.pid四、修改配置文件修改參數(shù)適配sftp服務(wù)同時(shí)在ssh服務(wù)中停掉sftp服務(wù)。修改sftpd配置文件vim/etc/ssh/sftpd_config 修改Port 22為Port 3322并去掉注釋。 修改#PidFile /var/run/sshd.pid為PidFile /var/run/sftpd.pid注釋掉Subsystem sftp/usr/local/openssh/libexec/sftp-server 在文件末尾增加以下內(nèi)容 Subsystem sftp internal-sftp Match User sftpuser##限制用戶(hù)ChrootDirectory/sftpdir##限制sftp目錄X11Forwarding no##與sftp無(wú)關(guān)所以關(guān)閉AllowTcpForwarding no##與sftp無(wú)關(guān)所以關(guān)閉PermitTTY no##不允許登入TTYForceCommand internal-sftp修改sshd配置文件vim/etc/ssh/sshd_config 取消注釋PidFile/var/run/sshd.pid 增加注釋#Subsystem即停掉sftp子服務(wù)五、分別重啟兩個(gè)服務(wù)systemctl restart sshd systemctl restart sftpd