连接虚拟机linux sftp,Linux虚拟机配置SFTP服务(备份服务器)

步骤1 配置磁盘

参考 Linux磁盘管理:LVM或Linux文件的 [磁盘管理:Linux新建数据盘] 章节。

步骤2 创建SFTP用户组与用户

groupadd sftpgrp //创建用户组

useradd -g sftpgrp -s /usr/sbin/nologin -M sftpuser //创建用户,-g用户组,-s不能登录,-M不创建用户目录。

chage -M 99999 sftpuser //修改用户密码不过期

passwd sftpuser //设置mysftp用户的密码

步骤3 配置SFTP目录

3.1

mkdir -p /backup/sftpuser //创建目录

3.2

usermod -d /backup/sftpuser sftpuser //指定用户目录,后面会用chroot指定

chown root:root /backup /backup/sftpuser

chmod 755 /backup /backup/sftpuser

3.3

//创建个不是chroot的、SFTP用户有权限写入的路径

cd /backup/sftpuser/

mkdir homepage

chown sftpuser:sftpgrp /backup/sftpuser/homepage

chmod 755 /backup/sftpuser/homepage

注意:

1、chroot要求1)目录及上级目录属主与属组需为root;2)只用属主有目录的写权限即最大755.

2、chroot目录属主与权限设置错误会导致sftp登录失败,作者经验:在步骤5使用“ChrootDirectory %h”指定路径是用户目录后,要确保3.2和3.3已执行且正确。

步骤4 配置selinux

vi /etc/selinux/config

SELINUX=disabled

SELINUX=permissive

setenforce 0

步骤5 配置/etc/ssh/sshd_config

vi /etc/ssh/sshd_config

//在132行左右注释下行

Subsystem sftp /usr/libexec/openssh/sftp-server

//增加下面这行

Subsystem sftp internal-sftp

//在文件的最后,因为Match结尾标志是新的Match或文件结尾,%h表示只能访问默认的用户目录

Match User sftpuser

Match Group sftpgrp

X11Forwarding no

AllowTcpForwarding no

ForceCommand internal-sftp

ChrootDirectory %h

//修改为以下

MaxSessions 100

//修改为以下

MaxStartups 100

service sshd restart

MaxSessions

Specifies the maximum number of open shell, login or subsystem

(e.g. sftp) sessions permitted per network connection. Multiple

sessions may be established by clients that support connection

multiplexing. Setting MaxSessions to 1 will effectively disable

session multiplexing, whereas setting it to 0 will prevent all

shell, login and subsystem sessions while still permitting for-

warding. The default is 10.

MaxStartups

Specifies the maximum number of concurrent unauthenticated con-

nections to the SSH daemon. Additional connections will be

dropped until authentication succeeds or the LoginGraceTime

expires for a connection. The default is 10:30:100.

Alternatively, random early drop can be enabled by specifying the

three colon separated values start:rate:full (e.g.

"10:30:60"). sshd(8) will refuse connection attempts with a

probability of rate/100 (30%) if there are currently

start'' (10) unauthenticated connections. The probability

increases linearly and all connection attempts are refused if the

number of unauthenticated connections reaches full (60).

步骤6 SFTP客户端登录验证

建议使用命令行 sftp sftpuser@[IPv6地址] 来接入验证,而不是直接用sftp客户端,如果连接失败起码有稍明显的报错。

FAQ

1、SFTP登录提示“Connection closed”

使用chage -l sftpuser查看返回结果的Password expires字段,一般是密码已经过期。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值