linux - SFTP - 覆盖权限(文件掩码、所有者/组)

标签 linux permissions sftp openssh

我正在运行 OpenSSH sftp 服务器(Linux、Raspbian),并使用 FileZilla 作为客户端。我遇到的问题是用户可以删除服务器上的任何文件,而不考虑文件掩码或所有者/组:

登录用户:

cat /etc/passwd | grep sftp     
sftp-guest:x:1001:1004:::/sbin/nologin

组:

cat /etc/group | grep sftp-only
sftp-only:x:1004:

这是我的/etc/ssh/sshd_config - 文件(影子端口):

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port ***33
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

#X11Forwarding yes
#X11DisplayOffset 10
#PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net
Banner /sftp/welcome_message

# Allow client to pass locale environment variables
#AcceptEnv LANG LC_*

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM yes

Subsystem sftp internal-sftp

Match group *,!sftp-only,!pi
        ForceCommand internal-sftp
        ChrootDirectory /sftp/empty

Match group sftp-only
        ChrootDirectory /sftp/%u
        AllowTCPForwarding no
        X11Forwarding no
        ForceCommand internal-sftp

正如您在 sshd_config 中看到的,用户 sftp-guest 已被 chroot 到/sftp/sftp-guest。
在这里您可以看到文件/文件夹的权限:

ll /sftp | grep sftp-guest
drwxr-xr-x  3 root root 4096 Dec 20 02:26 sftp-guest

ll /sftp/sftp-guest/
drwxrwxr-x 9 sftp-guest pi   4096 Apr 18 22:18 maturaprojekt

ll /sftp/sftp-guest/data/
---------- 1 sftp-guest sftp-only  205 Apr 18 22:06 readme
---------- 1 root       root       205 Apr 18 22:18 readme2

问题是这两个文件(readme、readme2)都可以使用 Filezilla 或通过 sftp(命令行)删除。可以进一步重命名或更改权限。

编辑 -->
当尝试查看或下载这些文件时,传输失败!
Filezilla-日志:

Command:    get "readme" "/tmp/fz3temp-1/readme"
Error:  /data/readme: open for read: permission denied
Error:  File transfer failed

Command:    get "readme" "/home/michael/data/readme"
Error:  /data/readme: open for read: permission denied
Error:  File transfer failed

<-- 编辑

我现在的问题是如何防止这种行为?

最佳答案

删除文件的权限在父文件夹上:如果该文件夹可写,则可以删除其中的文件。尝试使用 chmod -w/sftp/sftp-guest/data/ 来防止 sftp-guest 删除自述文件(您也可以使它们可读以修复您上次的编辑)。

关于linux - SFTP - 覆盖权限(文件掩码、所有者/组),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29723650/

相关文章:

linux - 影响启动它的交互式 shell 的脚本

linux - 将文件名插入 csv 文件的最后一列。

linux - Bash - 获取最近 12 小时的文件/复杂的名称格式

c# - SharpSSh : Restart file transfer if current file transfer too slow?

ruby-on-rails - 无法启动我的 Rails 服务器 [linux]

python - 如何访问 django rest 框架权限类中的 url 参数?

mysql - 重新为MySQL用户分配主机访问权限

PHP - 使用用户配置文件保护用户权限

python - 使用 Python (sftp) 更改远程 Linux 系统的密码

java - com.jcraft.jsch.ChannelSftp.get(String src,String dst) 会覆盖现有文件吗?