Intentando ChrootDirectory un usuario SFTP a su directorio de inicio

Intentando ChrootDirectory un usuario SFTP a su directorio de inicio

He seguido algunos ejemplos de cómo hacer esto, todos terminan modificándose sshd_configa

Subsystem sftp internal-sftp

Match User chubbyninja
    ChrootDirectory %h
    AllowTCPForwarding no
    X11Forwarding no
    ForceCommand /usr/lib/openssh/sftp-server

Cuando hago esto, me sshd -taseguro de que no haya errores.service sshd restart

una vez que se reinicia, intento SFTP (con filezilla) pero sigo obteniendo

Response:   fzSftp started
Command:    open "[email protected]" 22
Command:    Pass: ********************
Error:  Network error: Software caused connection abort
Error:  Could not connect to server

Si vuelvo la configuración a su estado original, puedo realizar SFTP bien, pero luego puedo explorar cualquier directorio. Donde necesito usuarios solo en su directorio de inicio

Mi configuración predeterminada tiene esta línea:

Subsystem sftp /usr/lib/openssh/sftp-server

Que es lo que soyreemplazandocon los detalles anteriores.

Sólo tengo acceso a esta máquina a través de ssh, aunque tengo acceso de root.

ACTUALIZAR Después de seguir el consejo de sam_pan_mariusz parece ir más lejos, pero ahora entiendo

Response:   fzSftp started
Command:    open "[email protected]" 22
Error:  Network error: Connection refused
Error:  Could not connect to server

ACTUALIZACIÓN 2

También seguí el consejo de Froggiz y cambié mi configuración a esta:

Subsystem sftp internal-sftp -u 0007 -f AUTH -l VERBOSE 
Match Group chubbyninja
     ChrootDirectory /home/chubbyninja
     ForceCommand internal-sftp -u 0007
     AllowTcpForwarding no
     GatewayPorts no
     X11Forwarding no

pero me sale el originalAborto de conexión en carcasa de software

Superviso /var/syslogpero no aparece nada que indique por qué hay este error

ACTUALIZACIÓN 3: sshd_config agregado

# 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 without-password
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

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp internal-sftp -u 0007 -f AUTH -l VERBOSE

# 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



Match Group chubbyninja
        ChrootDirectory /home/chubbyninja
        AllowTCPForwarding no
        X11Forwarding no
        GatewayPorts no
        ForceCommand internal-sftp -u 0007

Respuesta1

así es como configuro mi sftp para un usuario específico

1] crear un usuario

 adduser {USER}

2]editar /etc/ssh/sshd_config

 PasswordAuthentication yes 

 Subsystem sftp
 internal-sftp -u 0007 -f AUTH -l VERBOSE 
 Match Group {USER}
     ChrootDirectory {FOLDER}
     ForceCommand internal-sftp -u 0007
     AllowTcpForwarding no
     GatewayPorts no
     X11Forwarding no

3]establecer derechos para el usuario

 chmod -R 777 {FOLDER}

4]reiniciar ssh

service ssh restart

reemplace {USER} por su usuario y {FOLDER} por su carpeta y debería funcionar. ;)

¿Puedes poner tu configuración ssh completa?

Respuesta2

Realmente no entiendo la parte de "reemplazar" en la pregunta, pero... al hacer chroot en SSH,Comando de fuerzadebe hacer referencia al nombre del subsistema interno. En su caso, toda la línea debería decir: ForceCommand sftp.

Si desea utilizar la ruta ejecutable enChroot, tendrás que preparar el directorio chroot adecuado (que contenga bibliotecas a las que se vincula el ejecutable, configuraciones, etc.).

Líneas relevantes de mi configuración de trabajo:

Subsystem sftp /usr/lib/openssh/sftp-server

Match User testuser1
    ChrootDirectory /one/dir/path/
    ForceCommand internal-sftp

información relacionada