近期要给服务器设置一个SFTP用户,可以上传删除修改的SFTP,但是禁止该用户SSH登录。这里记录下来

先升级

yum update
2
 
1
yum update

fox.风

创建用户组 sftp

用户组名为sftp

groupadd sftp
x
 
1
groupadd sftp

创建用户 test

例如这个用户名为 test

useradd -G sftp -s /sbin/nologin test 
2
 
1
useradd -G sftp -s /sbin/nologin test 

-s 禁止用户ssh登陆 
-G 加入sftp 用户组

创建密码

passwd test 
2
 
1
passwd test 

修改配置文件sshd_config

vim /etc/ssh/sshd_config
2
 
1
vim /etc/ssh/sshd_config

修改为如下

....
##下面这行注释掉
#Subsystem sftp /usr/libexec/openssh/sftp-server
##后面加入
Subsystem sftp internal-sftp
#注意,以下要 放在 本文件的最后行,否则 root用户无法登陆
Match Group sftp
X11Forwarding no
AllowTcpForwarding no
ChrootDirectory %h
ForceCommand internal-sftp
x
 
1
....
2
##下面这行注释掉
3
#Subsystem sftp /usr/libexec/openssh/sftp-server
4
##后面加入
5
Subsystem sftp internal-sftp
6
#注意,以下要 放在 本文件的最后行,否则 root用户无法登陆
7
Match Group sftp
8
X11Forwarding no
9
AllowTcpForwarding no
10
ChrootDirectory %h                      
11
ForceCommand internal-sftp

说明 
Match Group sftp 匹配sftp用户组中的用户 
ChrootDirectory %h 只能访问默认的用户目录(自己的目录),例如 /home/test

设置目录权限

chown root:sftp /home/test
chgrp -R sftp /home/test
chmod -R 755 /home/test
#设置用户可以上传的目录,改目录下允许用户上传删除修改文件及文件夹
mkdir /home/test/upload
chown -R test:sftp /home/test/upload
chmod -R 755 /home/test/upload
x
9
 
1
chown root:sftp /home/test
2
chgrp -R sftp /home/test
3
chmod -R 755 /home/test
4
#设置用户可以上传的目录,改目录下允许用户上传删除修改文件及文件夹
5
mkdir /home/test/upload
6
chown -R test:sftp /home/test/upload
7
chmod -R 755 /home/test/upload

重启ssh

systemctl restart sshd.service
2
 
1
systemctl restart sshd.service

链接

新建一个 终端链接,或者在 FTP 客户端中使用SFTP 模式链接(输入相关的IP用户名及端口)

sftp test@192.1.1.1
2
 
1
sftp test@192.1.1.1

F&Q

如果报类似以下错误

sftp Connection to  closed by remote host.
或者
Write failed: Broken pipe
Couldn't read packet: Connection reset by peer
 
1
sftp Connection to  closed by remote host.
2
或者
3
Write failed: Broken pipe 
4
Couldn't read packet: Connection reset by peer 

Centos 7 设置 SFTP的更多相关文章

  1. 如何在 CentOS 中设置 NTP 服务器

    网络时间协议(NTP)用来同步网络上不同主机的系统时间.你管理的所有主机都可以和一个指定的被称为 NTP 服务器的时间服务器同步它们的时间.而另一方面,一个 NTP 服务器会将它的时间和任意公共 NT ...

  2. VMware于CentOS网络设置

    VMware于CentOS网络设置 底: 笔记本电脑有两块网卡: 1. 网卡连接公司内网,仅仅配置了内网ip和子网掩码. 2. 无线网卡.连接4g无线路由器.dhcp自己主动配置. 问题: 在VMwa ...

  3. CentOS 网络设置修改 指定IP地址 DNS 网关(转)

    CentOS 网络设置修改 指定IP地址 DNS 网关(实测 笔记)   环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Centos-6.5-x86_64 ...

  4. CentOS 网络设置

    CentOS 网络设置有两种方式配置网络可以连接外网: 自动分配与手动设置Ip 一,自动分配ip: 新装的centos6.0,用ifconfig只显示ifcfg-lo的信息,可以用ifup eth0的 ...

  5. linux centos 如何设置swap大小?

    linux centos 如何设置swap大小? swap的值都是安装系统的时候设置好的,一般设置为内存的两倍大小.使用过程中发现swap值过小只能添加.用free -m 命令查看当前swap大小 使 ...

  6. yum命令安装软件时,出现--centos 7 安装apache 出现 Could not resolve host: mirrorlist.centos.org; 未知的错误"--CentOS网络设置 couldn't resolve host 'mirrorlist.centos.org问题解决

    CentOS网络设置 couldn't resolve host 'mirrorlist.centos.org问题解决 今天在虚拟机上安装完CentOS6.5之后,首次使用时yum命令安装软件时,出现 ...

  7. centos 基础设置

    centos 6 关闭防火墙 查看防火墙是否开启 service iptables status 停止防火墙 service iptables stop 禁止开机自启动防火墙 chkconfig ip ...

  8. CentOS中设置Windows共享文件夹

    在CentOS中设置Samba可实现和Windows共享文件夹.常见的需求:1)用户能够在Windows机器上通过共享文件夹访问远程Linux服务器上自己的主目录:2)用户能够在Windows机器上访 ...

  9. Centos 7设置静态IP,修改时区,关闭防火墙

    Centos 7设置静态IP # vi /etc/sysconfig/network-scripts/ifcfg-enxxx BOOTPROTO="static" ...... I ...

随机推荐

  1. 常见web中间件漏洞(二)Apache漏洞

    Apache(总联想到武直那个)是最常见,使用人数最多的一款web服务器软件.跨平台,多扩展,开源,用过的人都说好 Apache的漏洞主要集中在解析漏洞这一块 1.未知扩展名解析漏洞 Apache的一 ...

  2. SQL 练习2

    查询同时存在" 01 "课程和" 02 "课程的情况 分析:分别先查询出包含有01课程和02课程 SELECT * from sc WHERE cid='01' ...

  3. NOIP 模拟 $34\; \rm Equation$

    题解 \(by\;zj\varphi\) 发现每个点的权值都可以表示成 \(\rm k\pm x\). 那么对于新增的方程,\(\rm x_u+x_v=k\pm x/0\) 且 \(\rm x_u+x ...

  4. redis搭建集群和主从

    说明 Redis集群至少需要3个节点,来支持投票容错机制,每个节点都有从节点,所有最少是6个服务(3个主3个从) 因为集群内置了16384个slot(哈希槽),并且把所有的物理节点映射到了这16384 ...

  5. docker部署minio

    快速部署 docker run -p 9000:9000 --name myminio \ -e "MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE" \ ...

  6. flutter 常用视图组件

    1.custom class widget main.dart 1 import 'package:flutter/material.dart'; 2 import './pages/custom.d ...

  7. WPF LiveChart 图表详解

    //参考网址:https://www.cnblogs.com/zh7791/p/12617961.html 本文主要介绍LiveChart.WPF 中的图表的使用方法 类: 数据绑定, 数据显示样式等 ...

  8. C++ com 组件的使用

    // CommonTest.cpp : This file contains the 'main' function. Program execution begins and ends there. ...

  9. wpf 中的 自定义控件的 binding

    XMl 代码 --------------------------------------------------------------------------------------------- ...

  10. springboot如何使用事物注解方式

    1.在启动类Application中添加注解@EnableTransactionManagement import tk.mybatis.spring.annotation.MapperScan; i ...