Skip to main content

SSH

Faire un SSH via un proxy : 
# Forward le trafic sur le port 8080 de mon ordinateur vers le port 80 de l'hote distant 
ssh -L 8080:localhost:80 remote_host

Supprimer un hostname des know_host ssh : 

ssh-keygen -R hostname

SSHD - Only sftp

Prérequits :

  • home de l'user toto : /opt/toto

Configuration /etc/ssh/sshd_config : 

Match User toto
     ChrootDirectory /opt/toto
     X11Forwarding no
     AllowTcpForwarding no
     AllowAgentForwarding no
     PasswordAuthentication no
     ForceCommand internal-sftp -d /%u

Commandes pour rendre la chose fonctionelle : 

mkdir /opt/toto/data
chown root:root /opt/toto
chown -R toto:toot /opt/toto/*
systemctl restard sshd

Test : 

sftp -i id_rsa toto@SERVEUR <<< 'put fichier.txt /data/'

# Test de perms
ssh -i id_rsa toto@SERVEUR
This service allows sftp connections only.
Connection to SERVEUR closed.

 

Lister les IP sources des sessions actuellements ouvertes (pas forcément ssh mais toi même tu sais) :  

loginctl | grep -v SESSION | awk '{print $1}' | xargs loginctl show-session | grep "RemoteHost=" | sort | uniq -c
   8084 RemoteHost=IP1
    107 RemoteHost=IP2
      1 RemoteHost=IP3