Ssh connexion très longue

Resuelto
tom45 -  
mamiemando Mensajes publicados 33228 Fecha de registro   Estado Moderador Última intervención   -
Hola Tengo un Linux CentOS 7. Quiero configurar un servidor SSH allí para transferir datos cifrados. He puesto la clave de mi servidor en la PC y desde mi servidor intento acceder con el comando ssh root@ip. Funciona sin pedir contraseña, como acordamos, pero después de un largo delay. He activado -v, pero no sé cómo entender qué va mal. ¿Puedes ayudarme por favor?
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to ip [ip] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.1.63:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: ***@*** MAC: <implicit> compression: none
debug1: kex: client->server cipher: ***@*** MAC: <implicit> compression: none
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-ed25519 SHA256:6AdxkZ4Wg9bhligStg1sQFvn0FE4PS84tAlnXjK+ZRI
debug1: Host 'ip' is known and matches the ED25519 host key.
debug1: Found key in /etc/ssh/ssh_known_hosts:18
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 535
debug1: Authentication succeeded (publickey).
Authenticated to ip ([ip]:22).
debug1: channel 0: new [client-session]
debug1: Requesting ***@***
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype ***@*** want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = fr_FR.UTF-8
Last login: Tue Jun 22 10:16:36 2021 from **.**.**.**
</rsa-sha2-256></implicit></implicit>

2 respuestas

mamiemando Mensajes publicados 33228 Fecha de registro   Estado Moderador Última intervención   7 940
 
Hola,

Probablemente se deba a la opción UseDNS definida en /etc/ssh/sshd_config.

Si la línea UseDNS Yes figura ahí:
- 1. Abre este archivo con privilegios de superusuario (p. ej. sudo nano /etc/ssh/sshd_config).
- 2. Comenta esta línea añadiendo un # al inicio de la línea, o corrígela a UseDNS yes.
- 3. Guarda y cierra (ctrl x, en nano)?
- 4. Reinicia el servidor ssh (sudo systemctl restart sshd.service) para que el cambio de configuración surta efecto.
- 5. Vuelve a intentar conectarte a tu servidor ssh.

Notas
- Indicas que te conectas con el usuario root. Es una mala idea, sobre todo si la máquina es accesible públicamente, porque el usuario root existe en toda máquina Linux, tiene máximo privilegios y, por tanto, es un blanco para un atacante. Por eso un servidor ssh bien configurado bloquea este tipo de conexión (también en /etc/ssh/sshd_config, ver PermitRootLogin no).
- Usa claves ssh, es muy buena idea, es más segura y limpia que la contraseña. Si solo piensas usar ese tipo de autenticación, puedes activar la opción PasswordAuthentication no en /etc/ssh/sshd_config.
- Para máxima seguridad, puedes completar la instalación con fail2ban.

Bonne suerte
1
tom45
 
Hello, it seems you shared a message in French containing configuration content. As per your request, I will provide a translation. Traduction en espagnol: Hola,

Gracias por tu ayuda

La línea ya estaba comentada ;( En relación a root, estoy en una red privada sin conexión a Internet y uso una conexión por clave ssh.

Aquí tienes una copia de mi archivo
/etc/ssh/sshd_config
:

# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/local/bin:/usr/bin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options override the # default value. # If you want to change the port on a SELinux system, you have to tell # SELinux about this change. # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER # #Port 22 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: 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 # Ciphers and keying #RekeyLimit default none # Logging #SyslogFacility AUTH SyslogFacility AUTHPRIV #LogLevel INFO # Authentication: #LoginGraceTime 2m #PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 #PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # HostbasedAuthentication # Change to yes if you don't trust ~/.ssh/known_hosts for # HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication no #PermitEmptyPasswords no PasswordAuthentication no # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes ChallengeResponseAuthentication no # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no #KerberosUseKuserok yes # GSSAPI options GSSAPIAuthentication no GSSAPICleanupCredentials no #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no #GSSAPIEnablek5users no # 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'. # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several # problems. UsePAM yes #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PermitTTY yes #PrintMotd yes #PrintLastLog yes #TCPKeepAlive yes #UseLogin no #UsePrivilegeSeparation sandbox #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #ShowPatchLevel no #UseDNS yes #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none #VersionAddendum none # no default banner path #Banner none # Accept locale-related environment variables AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE AcceptEnv XMODIFIERS # override default of no subsystems Subsystem sftp /usr/libexec/openssh/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server
0
tom45
 
Eres un genio, llevo 2 días buscando, pfiouuu.

Muchas gracias, he quitado el # y lo puse en no, funciona.

Gracias, gracias.

Te deseo un excelente día.

y gracias por todos tus consejos.
0
mamiemando Mensajes publicados 33228 Fecha de registro   Estado Moderador Última intervención   7 940 > tom45
 
Hola de nuevo Tom

De nada, de hecho ya tuve este problema en el pasado, por eso :-)

Buena continuación y que tengas un excelente día también
0
mamiemando Mensajes publicados 33228 Fecha de registro   Estado Moderador Última intervención   7 940
 
Hola Tom,

Tu archivo de configuración me parece correcto, pero intenta poner explícitamente
UseDNS no
. Verifica también que el nombre de tu máquina esté definido en
/etc/hosts
.

Ejemplo : Aquí mi máquina se llama
silk
como indica el comando
hostname
, y encuentro bien esta entrada en
/etc/hosts
.

(mando@silk) (~) $ grep $(hostname) /etc/hosts
127.0.1.1 silk


A modo indicativo, aquí está el contenido de
/etc/ssh/sshd_config
definido en uno de los servidores que gestiono (ver
grep -v ^# /etc/ssh/sshd_config | grep -v ^$
) :

Include /etc/ssh/sshd_config.d/*.conf
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
X11Forwarding yes
PrintMotd no
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server


Bonne chance
0