无法通过我的机器上的ssh登录


1

每当我将用户添加到“sftp”组以便我可以使用chroot时我就不能再通过SSH连接它说:“ 无法将chdir连接到主目录/ home / sftp_user:没有这样的文件或目录 ”和“ 此服务允许仅sftp连接 “。如果我将/ home / sftp_user的所有者设置为sftp_user,那么我可以登录但chroot不再起作用。我该如何解决这个问题,以便我能够SSH和使用chroot(仅限SFTP而不是SSH)?

# 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
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

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

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin no
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 no
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 internal-sftp

# 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 yes".
# 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

Match Group sftp
        ChrootDirectory %h
        ForceCommand internal-sftp
        AllowTcpForwarding no
linux  ssh  sftp  chroot 

编辑您的问题以包含服务器上sshd配置文件中的所有相关行。
Kenster

Answers:


0

其实我不认为你问的是可能的。

从sshd_config手册:

 ChrootDirectory
         Specifies the pathname of a directory to chroot(2) to after
         authentication.  At session startup sshd(8) checks that all
         components of the pathname are root-owned directories which are
         not writable by any other user or group.  After the chroot,
         sshd(8) changes the working directory to the user's home
         directory.

因此,要使chroot工作,目录必须是root用户。这就是更改/ home / sftp_user的所有者时它不起作用的原因。

另一方面,当所有者是正确的chroot工作,但您正在尝试访问chroot之外的路径(您的主目录)。如果您希望这个工作,您将需要在chroot内创建主文件夹。因此,如果你被chroot到/ home / sftp_user,你将需要创建/ home / sftp_user / home / sftp_user。

当连接时,sshd无法判断你是否想要“ssh”或“sftp”。因此,您需要使用其他方法进行区分。也许是sftp特定帐户或其他东西。


是的我想我必须使用不同的帐户。:(无论如何,谢谢你
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.