gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:16:12 29 4
gpt4 key购买 nike

我正在运行 OpenSSH sftp-server(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

问题是这两个文件(自述文件、自述文件 2)都可以使用 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com