Guides pour configurer et durcir ssh:
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
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.
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)
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
Permet de monter un filesystem distant via ssh
sshfs -p <port> user@sftp-server.net:/home/user/ local-folder
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 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 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
SSH scanning ssh-blacklist
Blacklister les Ips indésirables avec le script http://www.frit.net/scripts/ copie locale
SFTP Only Chroot Jail (OpenSSH v5)
SFTP Only Chroot Jail (OpenSSH 4)
Chroot sftp: solution sftponly, bind et acl : accès sécurisé sur un serveur de sauvegarde
Ssh tunneling (Encrypt your HTTP Traffic and more):
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
ssh -C -NL 9999:localhost:5900 USER@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
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 <public port> -t -A root@<public ip> ssh -t root@<private-ip>
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