====== Secure SHell (SSH) ====== * https://man.openbsd.org/sshd_config Guides pour configurer et durcir ssh: - https://www.digitalocean.com/community/tutorials/ssh-essentials-working-with-ssh-servers-clients-and-keys - https://infosec.mozilla.org/guidelines/openssh ===== Configuration ===== Afficher et tester la configuration complète (variables config & default) : # Afficher et tester sudo sshd -T # Juste tester sudo sshd -t Dans /etc/ssh/sshd_config tu change la ligne PermitRootLogin Yes en PermitRootLogin No Et si tu veux autoriser l'accès ssh en root uniquement avec clé ssh tu mets : PermitRootLogin without-password Une configuration solide: # /etc/ssh/sshd_config.d/99_custom.conf #Port non standard: réduit le bruit malveillants MaxAuthTries 3 LoginGraceTime 5 PermitRootLogin no PasswordAuthentication no PermitEmptyPasswords no KbdInteractiveAuthentication no #ChallengeResponseAuthentication no HostbasedAuthentication no KerberosAuthentication no GSSAPIAuthentication no PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 StrictModes yes Compression no AllowTcpForwarding no X11Forwarding no AllowAgentForwarding no AllowStreamLocalForwarding no IgnoreRhosts yes #UsePAM yes ??? # - ^=^s Check which modules are active HostKeyAlgorithms ssh-ed25519,rsa-sha2-512 PubkeyAcceptedKeyTypes ssh-ed25519,rsa-sha2-512,rsa-sha2-256 MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com # remove LC_* to avoid some "Can't set locale; make sure $LC_* and $LANG are correct!" AcceptEnv LANG ClientAliveInterval 20 ClientAliveCountMax 2 TCPKeepAlive yes ===== Clients ===== ==== ClusterSSH ==== http://sourceforge.net/apps/mediawiki/clusterssh/ ClusterSSH is a tool for making the same change on multiple servers at the same time. The 'cssh' command opens an administration console and an xterm to all specified hosts. Any text typed into the administration console is replicated to all windows. All windows may also be typed into directly. This tool is intended for (but not limited to) cluster administration where the same configuration or commands must be run on each node within the cluster. Performing these commands all at once via this tool ensures all nodes are kept in sync. ==== Clients pour Windows ==== Tunnelier : http://www.bitvise.com/tunnelier.html PuTTY : [[http://www.putty.org/]], https://www.chiark.greenend.org.uk/~sgtatham/putty/ SharpSSH - A Secure Shell (SSH) library for .NET: http://www.tamirgal.com/blog/page/SharpSSH.aspx (old: 2007) ==== Linux Keychain Guide ==== * Keychain http://www.gentoo.org/doc/en/keychain-guide.xml, http://manpages.ubuntu.com/manpages/intrepid/man1/keychain.1.html, [[https://help.ubuntu.com/community/QuickTips#Tip%20#3%20Keychain%20-%20Manage%20ssh%20keys]] * [[http://live.gnome.org/GnomeKeyring|GNOME Keyring]], [[wpen>GNOME_Keyring]], [[http://library.gnome.org/devel/gnome-keyring/stable/|gnome-keyring Reference Manual]] * ssh-agent ==== sshfs ==== Permet de monter un filesystem distant via ssh * https://doc.ubuntu-fr.org/sshfs sshfs -p user@sftp-server.net:/home/user/ local-folder ===== Tips ===== ==== Logs ==== > comment demander gentilement a sshd de logger tout ce qui se passe connexion/deconnexions dans un fichier /var/log/sshd.log ? voir /etc/syslog.conf # ATTENTION : local5 est utilisé notamment par sshd local5.info /var/log/sshd Le port 22 est scanné en permanence, ce qui rempli le disque (risque [[glossaire/DDOS]]): root@seriously:~# ls -lhS /var/log/|head total 13M -rw-rw---- 1 root utmp 36M Jul 10 12:09 btmp -rw-r----- 1 root adm 25M Jul 4 06:13 auth.log.1 -rw-r----- 1 root adm 24M Jul 10 12:09 auth.log -rw------- 1 root utmp 13M Jul 1 06:12 btmp.1 ==== Email automatique lors de la connexion ==== Email automatique pour toute connexion ssh: créer le fichier /etc/ssh/sshrc avec: email="$USER@"`hostname` ldate=`date "+%A %e %B %Y à %Hh%M %Z"` echo -e "Bonjour,\n\nUne session SSH version $SHLVL à été ouverte\n\ncompte: $email\n\ndate: $ldate\n\nconnexion: $SSH_CONNECTION." | mail -s "connexion ssh" monemail@mondomaine.com ==== Blacklister les Ips indésirables ==== SSH scanning ssh-blacklist Blacklister les Ips indésirables avec le script http://www.frit.net/scripts/ {{:informatique:ssh-blacklist.zip|copie locale}} ==== Chroot Jail ==== [[http://adamsworld.name/chrootjailv5.php|SFTP Only Chroot Jail (OpenSSH v5)]] [[http://adamsworld.name/chrootjailv4.php|SFTP Only Chroot Jail (OpenSSH 4)]] [[http://shnoulle.net/Chroot-sftp-solution-sftponly-bind|Chroot sftp: solution sftponly, bind et acl : accès sécurisé sur un serveur de sauvegarde]] RSSH: http://www.pizzashack.org/rssh ==== Tunnel ==== Ssh tunneling (Encrypt your HTTP Traffic and more): * https://www.digitalocean.com/community/tutorials/ssh-essentials-working-with-ssh-servers-clients-and-keys#setting-up-ssh-tunnels Vous créez un port d'écoute qui se charge de prendre toute trame réseau qui rentre “telle quelle” et de la faire exécuter depuis l'autre bout du tunnel. ssh -D port-local nomutilisateur@nomhôte === Forwarding === ssh -C -NL 9999:localhost:5900 USER@REMOTE_HOST * -C parameter to compress data (optional - useful for low bandwidth connections) * -N parameter to not execute a remote command (i.e. no prompt on the remote machine) * -L parameter for port forwarding from port 9999 on localhost to port 5900 on REMOTE_HOST. Ne fonctionne pas toujours avec 'localhost', utiliser alors '127.0.0.1' ssh -N -L 127.0.0.1:3307:127.0.0.1:3306 -p 30001 USER@REMOTE_HOST === Proxying === scp -o 'ProxyJump user@proxy.openstreetmap.fr' ./file user@vm.openstreetmap.fr:/home/user/ Se connecter à un serveur via un autre serveur (forwarding agent): ssh -p -t -A root@ ssh -t root@ proxying (JumpHost): ssh -J jump-user@jump.net:1234 destination-user@destination.net Via la configuration du client SSH, ce qui du coup fonctionne avec SCP: #~/.ssh/config Host machineC ProxyCommand ssh -p XXX user@machineB nc %h %p host un-nom-raccourci Hostname destination.finale.net ProxyCommand ssh -p 666 -W %h:22 user-passerelle@passerelle.ssh.net User user-destination IdentityFile $SSHKEY Ouvrir une console via une autre machine: ssh -t -A toto@s1.artefacts.coop ssh -t toto@s2.artefacts.coop