= configuración ssh server (/etc/ssh/sshd_config) * comprobar si hay restricciones en IPTABLES ''/etc/sysconfig/iptables'' * se puede limitar el uso que se puede hacer de SSH en el siguiente fichero: ''/etc/ssh/sshd_config'' * Opciones destacadas: * **Protocol 2** * **PermitRootLogin** {yes|no|forced-commands-only} * **PasswordAuthentication** {yes|no}: uso o no de contraseña (forzar uso de keys) * **IgnoreRhosts** {yes|no} evita la lectura de los ficheros ~/.rhosts y ~/.shosts * **Banner** /etc/fichero * **Port 22** * **ListenAddress 192.168.1.1** * **PermitEmptyPasswords** {yes|no} * **ClientAliveInterval ** * **ClientAliveCountMax <#>** número de veces que comprueba actividad, según intervalo de **ClientAliveInterval** * **LogLevel INFO** * **AllowUsers** solo los usuarios que se pueden conectar vía SSH * **DenyUsers** a los usuarios que NO se pueden conectar vía SSH * AllowGroups * DenyGroups * curso lpic2: [[info:cursos:pue:lpic2-2021:s14#ssh]] * [[http://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html|Fuente]] * [[http://www.debian-administration.org/articles/590|chroot con SSH]] * [[http://en.wikipedia.org/wiki/Port_knocking|Port knocking]] * [[http://www.debian-administration.org/articles/268|Multiple-port knocking Netfilter/IPtables only implementation]] == restricciones === agent forwarding Match User that-restricted-guy AllowTcpForwarding yes X11Forwarding no AllowAgentForwarding no ForceCommand /bin/false Match User even-more-restricted-guy PermitOpen 127.0.0.1:12345 X11Forwarding no AllowAgentForwarding no ForceCommand /bin/false * Solo permite forward de conexiones a 127.0.0.1 * para evitar la desconexión y mantener la conexión de reenvio abierta, deberá usar **-N** en su conexión **ssh**:ssh -L 12345:127.0.0.1:12345 -N even-more-restricted-guy@insert-your-machine Match Group nicepeople PubkeyAuthentication yes PasswordAuthentication yes PermitEmptyPasswords no GatewayPorts no ChrootDirectory /opt/dummy_location/%u ForceCommand internal-sftp AllowTcpForwarding yes PermitOpen 192.168.0.8:22 PermitOpen 192.168.0.5:8080 # Or leave out the PermitOpen to allow forwarding to anywhere. HostbasedAuthentication no RhostsRSAAuthentication no AllowAgentForwarding no Banner none Restringir acceso a la red: /sbin/iptables -I OUTPUT -m owner --gid-owner 500 -j REJECT /sbin/iptables -I OUTPUT -m owner --gid-owner 500 -m tcp -p tcp -d 192.168.0.0/24 -j ACCEPT /via: [[https://unix.stackexchange.com/questions/14312/how-to-restrict-an-ssh-user-to-only-allow-ssh-tunneling]]\\ /more: [[https://superuser.com/questions/229743/howto-disable-ssh-local-port-forwarding]]