# 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
现在在这种情况下david可以使用say filezilla客户端sftp,并且他被chroot到/ var / chroot-home / david /.但是,如果我要设置无密码身份验证呢?我已经尝试将他的密钥粘贴在/var/chroot-home/david/.ssh/authorized_keys中但没有用,尝试ssh’ing作为大卫到框中它只是停在“debug1:发送env LC_CTYPE = C”后我供应它的密码并没有在auth.log中显示,可能是因为它无法找到homedir.如果我以root身份“su – david”,我会看到“没有目录,使用HOME = /登录”这是有道理的. Symlink也没有帮助.
我也尝试过:
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抱怨错误的所有权或权限模式,如果我这样做,david不能再直接在他的家中上传/删除任何东西,同时使用sftp FileZilla的.
解决方法
第二点需要注意的是:在你的第一个设置中,当david登录时,他在/ var / chroot-home / david中启动,但他实际上是chroot到/ var / chroot-home,这意味着如果他输入cd ..他可以看到所有其他家庭目的(虽然不是他们的内容,如果权限是正确的).这对你来说可能是也可能不是问题,但要注意这是一件好事.
如果以上情况适合你,你可以使用你的第一个sshd_config,在passwd文件中将david的home目录设置为/ var / chroot-home / david,并添加以下符号链接,以便david仍然在他的主目录中启动:
cd /var/chroot-home mkdir var ln -s .. var/chroot-home
该符号链接将确保您可以使用相同的路径到达主目录,无论您是否在chroot中.
但是,如果您不希望客户端看到彼此主目录的名称,则需要chroot到主目录本身,就像在第二个解决方案中一样.但正如您所见,sshd并不喜欢(因为出于各种微妙的原因,给用户写入文件系统根目录的访问权限是危险的).可悲的是,你在这里几乎没有运气.一个(kludgy)解决方案是在每个主目录中创建一个文件/子目录,并为客户端提供对该目录的写访问权.
另一种选择可能是chroot到/ var / chroot-home,并且不同地命名主目录,例如使用用户ID号而不是名称.