美文网首页
sftp与ssh端口分开

sftp与ssh端口分开

作者: 乘以零 | 来源:发表于2023-12-27 16:18 被阅读0次
cp /etc/ssh/sshd_config /etc/ssh/sftpd_config
vi /etc/ssh/sftpd_config

# 设置sftp端口
Port 20022

PidFile /var/run/sftpd.pid # 设置sftp进程文件
PermitRootLogin no    #禁止root登录
PasswordAuthentication yes
Match Group sftp  #用户组
ChrootDirectory  /home/%u
ForceCommand internal-sftp    # 只能用于sftp
AllowTcpForwarding no         # 禁止TCP转发
X11Forwarding no              # 禁止X11转发
## 新加的配置都放到最后 修改的配置可以放在原来的行数
# 服务分离
cp /usr/lib/systemd/system/sshd.service /etc/systemd/system/sftpd.service
cp /etc/pam.d/sshd /etc/pam.d/sftpd
cp /etc/sysconfig/sshd  /etc/sysconfig/sftp
vi /etc/systemd/system/sftpd.service

Description=sftpd server daemon
# 配置文件从sshd改成sftp专用的
EnvironmentFile=/etc/sysconfig/sftp
# sftp服务绑定sftp、配置文件
ExecStart=/usr/sbin/sftpd -f /etc/ssh/sftpd_config
ln -sf  /usr/sbin/service  /usr/sbin/rcsftpd
ln -sf  /usr/sbin/sshd  /usr/sbin/sftpd

touch /var/run/sftpd.pid
groupadd sftp
useradd -g sftp -s /bin/false citic
passwd citic

chown root:sftp /home/citic
chmod 755 /home/citic

mkdir /home/citic/upload
chown citic:sftp /home/citic/upload
chmod 755 /home/citic/upload


setenforce 0
# 重启sftpd服务
systemctl restart sftpd.service
ssh只允许指定的用户登陆(同样适用于sftp)
    方法1:在/etc/pam.d/sshd文件第一行加入
        auth required pam_listfile.so item=user sense=allow file=/etc/sshusers onerr=fail
        然后在/etc下建立sshusers文件,编辑这个文件,加入你允许使用ssh服务的用户名,不用重新启动sshd服务。
    方法2:pam规则也可以写成deny的
        auth required pam_listfile.so item=user sense=deny file=/etc/sshusers onerr=succeed
    方法3:在sshd_config中设置AllowUsers,格式如
        AllowUsers a b c
    重启sshd服务,则只有a/b/c3个用户可以登陆

(第三种对我无效 不知道为啥)

相关文章

网友评论

      本文标题:sftp与ssh端口分开

      本文链接:https://www.haomeiwen.com/subject/uknrndtx.html