部署ftp

xiaoxiao2021-02-28  79

ftp部署

一、安装

yum install vsftpd

二、配置

/etc/vsftpd/vsftpd.conf

anonymous_enable=NO //不用虚拟用户 local_enable=YES //继承Linux本地用户 write_enable=YES //本地用户写权限

chroot_local_user=YES //所有用户都只能访问当前home目录(以home目录为 / 目录) chroot_list_enable=YES //启用chroot_list_file(例外用户名单) chroot_list_file=/etc/vsftpd/chroot_filelist //免疫chroot_local_user效果的用户名单

userlist_deny=NO //user_list文件记录的用户允许登入ftp,文件中未包括的用户账号被禁止FTP登录。 vsftp文件

[转载] 配置ftp用户无法ssh登入服务器

原文链接https://blog.csdn.net/qq_35440678/article/details/52788808

背景

基于对线上服务器的保密和安全,不希望开发人员直接登录线上服务器,因为登录服务器的权限太多难以管控,能限制开发人员ssh登录机器,但是通过ftp/sftp上传代码文件。

在网上找个各种各样的方法,经过试验做个汇总:

方法一

https://segmentfault.com/q/1010000000722462 这篇帖子的方法是搜索到的最通用的方法,方法是否可能呢,直接做个测试。

创建禁止登陆的用户:

useradd test -M -s /sbin/nologin 试试ssh登陆:登陆失败

[root@localhost app]# ssh test@172.19.194.30 test@172.19.194.30’s password: Last login: Tue Oct 11 15:28:07 2016 from 172.18.135.185 This account is currently not available. Connection to 172.19.194.30 closed. 试试sftp登陆:同样也提示登陆失败!!!

[root@localhost app]# sftp test@172.19.194.30 test@172.19.194.30’s password: Received message too long 1416128883 [root@localhost app]# 可以看到,方法一,虽然限制了ssh登陆,但是同时也限制了sftp的连接,结论是当前方法不可行。

方法二

http://jin771998569.blog.51cto.com/2147853/1067247 首先修改sshd的配置文件:

#vim /etc/ssh/sshd_config #该行(上面这行)注释掉 #Subsystem sftp /usr/lib/openssh/sftp-server # 添加以下几行 Subsystem sftp internal-sftp Match group sftp #Match user test #匹配sftp组,如为单个用户可用:Match user 用户名; 设置此用户登陆时的shell设为/bin/false,这样它就不能用ssh只能用sftp ChrootDirectory /home/test #指定用户被锁定到的那个目录,为了能够chroot成功,该目录必须属主是root,并且其他用户或组不能写 X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp

添加用户组和用户 #添加用户组 groupadd sftp #添加用户 useradd -d /home/test -m -s /bin/false -g sftp test #修改密码 passwd test 重启SSH服务 service sshd restart 或者

/etc/init.d/ssh reload 测试ssh [root@localhost etc]# ssh test@172.19.194.30 test@172.19.194.30’s password: Write failed: Broken pipe 登陆失败,提示Write failed: Broken pipe错误

再测试sftp [root@localhost etc]# sftp test@172.19.194.30 test@172.19.194.30’s password: Write failed: Broken pipe Couldn’t read packet: Connection reset by peer 同样提示Write failed: Broken pipe

按理说此方法应该是靠谱的为什么会提示失败呢,通过查找发现是目录权限配置导致的: https://my.oschina.net/davehe/blog/100280 目录权限设置上要遵循2点: ChrootDirectory设置的目录权限及其所有的上级文件夹权限,属主和属组必须是root; ChrootDirectory设置的目录权限及其所有的上级文件夹权限,只有属主能拥有写权限,权限最大设置只能是755。 修改/home/test 目录权限为755

chmod 755 /home/test -R 再次测试 [root@localhost etc]# ssh test@172.19.194.30 test@172.19.194.30’s password: Could not chdir to home directory /home/test: No such file or directory This service allows sftp connections only. Connection to 172.19.194.30 closed. 和预期一致:ssh尝试连接失败。

[root@localhost etc]# sftp test@172.19.194.30 test@172.19.194.30’s password: Connected to 172.19.194.30. sftp> ls a a.log authorized_keys mysql.sh sftp> sftp测试连接成功!

总结

这个东西虽然没有太大的技术含量,但是通过网上查找的大多是雷同且行不通的,又或者是不完整的,过程中耽误和浪费了不少时间,希望写这篇博客做个验证和汇总的作用。

转载请注明原文地址: https://www.6miu.com/read-2350351.html

最新回复(0)