大网数据广告活动
服务器运维问答

How can I disable sftp temporarily without reloading the service?

· 52CE 我爱测

I've set up a user with chroot that has access to only 1 directory through sshd's sftp so that one of my coworkers can upload certain kinds of files. I'm then going to make a way to trigger a command through HTTP that will run a …

问题原文

原帖链接 · Roberto Arosemena · CC BY-SA 3.0

I've set up a user with chroot that has access to only 1 directory through sshd's sftp so that one of my coworkers can upload certain kinds of files. I'm then going to make a way to trigger a command through HTTP that will run a long process on the files, and I need to disable sftp while the process is being run.

Is there a command I can use to disable sftp without having to change the sshd_config file and reload the service? I was thinking of doing port blocking, but I still need access to ssh.

I read about disabling the user account with passwd -l, but if it's already logged in through sftp it would still allow modification.

Any suggestions?

Edit:

After some more dabbling I found out that I could do ps -axl | grep $user@notty and send a kill -9 to the PID to disconnect the user from It's current session and then either do passwd -l username to prevent the user from logging in again or as Martin suggested remove the symlink to the sftp-server binary.

But in the end I took Mike's advice and just moved the files somewhere else instead of running the process in the chroot directory.

已采纳解答

原帖链接 · Martin Prikryl · CC BY-SA 4.0

You can temporarily remove write permissions to the folder.


If you want to disable SFTP completely, you can create a symlink to sftp-server binary. And configure the user to use that symlink as SFTP binary. Then you can just temporarily remove the symlink, what will effectively disable the SFTP.

Match User theuser
    ForceCommand /path/to/sftp/symlink

Note that removing the symlink won't terminate existing SFTP sessions. You have to kill all user-owned processes of sftp-server.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。