惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
V
V2EX
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
Kaspersky official blog
S
Secure Thoughts
T
Tenable Blog
Security Latest
Security Latest
The Cloudflare Blog
S
Security @ Cisco Blogs
H
Heimdal Security Blog
aimingoo的专栏
aimingoo的专栏
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
IT之家
IT之家
Latest news
Latest news
The Hacker News
The Hacker News
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
N
News | PayPal Newsroom
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
S
Security Affairs
S
Securelist
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
A
About on SuperTechFans

Feel.name

Centos7安装sngrep – Feel.name DNS大全 – Feel.name Linux下转换文件编码 – Feel.name Linux服务器密钥登陆方法 – Feel.name 升级到最新OpenSSH_9.3p1, OpenSSL 3.1.1 – Feel.name linux清理缓存(cache) – Feel.name 通过yum来下载RPM包的方法 – Feel.name 年末守望新年期盼 – Feel.name message 日志里面的“Created slice User Slice of root.”日志去除方法 – Feel.name
centos 7上创建sftp服务 – Feel.name
Feel · 2023-06-20 · via Feel.name

Skip to content

环境:centos7

注意:服务器 OpenSSH-Server 版本最低4.8,用 ssh –V 来查看openssh的版本,如果低于4.8,需要自行升级安装。

[root@localhost home]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017

sftp优点:sftp比ftp更可取,加密传输,设置也简单。ftp过于繁琐,且是不安全的协议

开启用户SFTP服务

创建sftp组
groupadd sftp
创建测试账户
sudo useradd -g sftp -s /sbin/nologin -M testuser
参数说明:

-g              # 加入用户组
-s              # 指定用户登入后所使用的shell
/sbin/nologin   # 用户不允许登录
-M              # 不要自动建立用户的登入目录

设置用户密码:

passwd testuser
Changing password for user testuser.
New password:

创建目录

mkdir /opt/sftp
cd /opt/sftp
mkdir testuser

设置sftp组根目录权限

chown root:sftp /opt/sftp
chmod 755 /opt/sftp

文件夹所有者必须是root,用户组可以不是root。

设置具体的用户根目录权限:

chown www:sftp -R /opt/sftp/testuser
chmod 775 -R /opt/sftp/testuser

修改测试账户HOME路径:usermod -d /opt/sftp/testuser testuser

配置sshd_config :

vim /etc/ssh/sshd_config
注释掉:Subsystem sftp /usr/libexec/openssh/sftp-server
添加如下几行:

Subsystem  sftp  internal-sftp # 开启sftp
Match Group sftp  # 限制的用户组
ChrootDirectory /opt/sftp/%u  # 根目录
ForceCommand internal-sftp  
AllowTcpForwarding no  
X11Forwarding no  

检测配置:shd -t
重启sshd服务:service sshd restart
测试连接:密码登录:sftp -P 22 testuser@127.0.0.1,密钥登录:sftp -P 22 -i ~/.ssh/id_rsa testuser@127.0.0.1

done!