我有chrooted sftp设置如下。
# Package generated configuration file # See the sshd_config(5) manpage for details # What ports, IPs and protocols we listen for Port 22 # 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 #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 without-password StrictModes yes AllowGroups admins clients 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 # Allow client to pass locale environment variables AcceptEnv LANG LC_* #Subsystem sftp /usr/lib/openssh/sftp-server # 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 clients ChrootDirectory /var/chroot-home X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp
一个虚拟用户
root:~# tail -n1 /etc/passwd david:x:1000:1001::/david:/bin/sh
现在在这种情况下,大卫可以sftp使用说filezilla客户端,他被chrooted到/ var / chroot-home / david /。 但是,如果我要设置无密码身份validation呢? 我已经尝试粘贴/var/chroot-home/david/.ssh/authorized_keys中的密钥,但没有用,试图ssh'ing作为大卫的框,它只是停止在“debug1:发送env LC_CTYPE = C”后,我供应它的密码并没有在auth.log中显示,可能是因为找不到homedir。 如果我做“su – david”作为根我看到“没有目录,login与HOME = /”这是有道理的。 符号链接也没有帮助。
我也尝试过:
Match group clients ChrootDirectory /var/chroot-home/%u X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp
一个虚拟用户
root:~# tail -n1 /etc/passwd david:x:1000:1001::/var/chroot-home/david:/bin/sh
这样,如果我不改变/ var / chroot-home / david为root:root sshd抱怨不好的所有权或权限模式,如果我这样做,大卫不能再上传/删除任何东西,直接在他家使用sftp FileZilla的。
首先, /etc/passwd的主目录应该反映出未连接的path,否则一般会遇到问题。 在这种情况下, sshd在chroot之前检查授权密钥,因此需要使用un-chrootedpath来查找它们。 这就是为什么你的第一次尝试不起作用。
第二件事要注意:在你的第一个设置,大卫login时,他开始在/var/chroot-home/david ,但他实际上是chrooted到/var/chroot-home ,这意味着如果他键入cd ..他可以看到所有其他家庭的dirs(虽然不是他们的内容,如果权限是正确的)。 这对你来说可能是也可能不是问题,但是要注意是件好事。
如果上面的问题没有问题,你可以使用你的第一个sshd_config,把david的主目录设置为/var/chroot-home/david到passwd文件中,然后添加下面的符号链接,以便david仍然在他的主目录下:
cd /var/chroot-home mkdir var ln -s .. var/chroot-home
该符号链接将确保您可以使用相同的path到达主目录,无论您是否在chroot中。
但是,如果您不希望客户端看到彼此主目录的名称,则需要将其作为主目录本身,就像在第二个解决scheme中那样。 但是正如你所看到的, sshd不喜欢这样(因为各种微妙的原因,给用户写一个文件系统的根权限是很危险的)。 可悲的是,你们在这里几乎不走运。 一个(kludgy)解决scheme是在每个主目录中创build一个files/子目录,并赋予客户端对其的写权限。
另一种select是将chroot改为/ var / chroot-home,然后以不同的方式命名主目录,例如使用用户标识号而不是名称。
我用这个解决了这个问题:
AuthorizedKeysFile /sftp/%u/.ssh/authorized_keys
其中%u是正在logging的chroot用户。
Match Group sftp ChrootDirectory /sftp/%u
你检查了.ssh和authorized_keys的文件权限吗?
drwx------ .ssh/ (chmod 0700) -rw------- .ssh/authorized_keys (chomd 0600)
这可能是显而易见的,但有时却被忽视了。
您需要在用户的chroot home(/ var / chroot-home / david / incoming或其他)中创build一个子目录,然后chown david:clients incoming并使用chmod 755 incoming适当的权限。
详情请看这个post 。
我发现我必须创build一个chroot home(如上所述),而且还要创build一个真正的home(/ home / david)来存储他们的.ssh / authorized_keys文件。 我相信这是因为SSHauthentication发生在chroot之前,所以sshd不知道在那里查找.ssh文件。
现在想想看,我可能会再次尝试使用他们真正的主目录作为他们的chroot home:仍然需要创build一个incoming文件夹,但至less.ssh将会在预期的位置。