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

时间:2015-04-18 22:30:38

标签: linux permissions sftp openssh

我正在运行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

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

编辑 - >
当试图查看或下载这些文件时,转移失败! 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

< - 编辑

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

1 个答案:

答案 0 :(得分:2)

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