Afficher la révision 31
+Les clefs publique/privées
Génération d'un couple privé/public
prompt>ssh-keygen -t rsa
prompt> ...
Genération sur stdout de la clef publique
prompt>ssh-keygen -y
Enter file in which the key is (/home/cmic/.ssh/id_rsa):
Enter passphrase:
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAou8RMHFoX6J0wH9N33rGmS?
AiyBiCEs0rAy9znwOIBxdtcTsWvVSXyF0ZW2IGzUrVZLdfAcs3BKXrn9CM?
d2Iqarl7tpc+B1Z+LdGId1WpTRNh1I1bL5Bo29OKDZr?+vknTDM7xELQbRm?
7qtAkwMRRCxty7JEaM3ostEBgLGgN9Fek?=
Genération sur stdout de la clef publique SECSH Public Key File Format
prompt>ssh-keygen -e
Enter file in which the key is (/home/cmic/.ssh/id_rsa):
- BEGIN SSH2 PUBLIC KEY -
Comment: "1024-bit RSA, converted from OpenSSH? by cmic@zombie"
AAAAB3NzaC1yc2EAAAABIwAAAIEAou8RMHFoX6J0wH9N33rGmSAiyBiCEs0rAy9znwOIBx?
dtcTsWvVSXyF0ZW2IGzUrVZLdfAcs3BKXrn9CMd2Iqarl7tpc?+B1Z+LdGId1WpTRNh1I1b?
L5Bo29OKDZr+vknTDM7xELQbRm7qtAkwMRRCxty7JEaM3ostEBgLGgN9Fek?=
- END SSH2 PUBLIC KEY -
Génération de l'empreinte (fingerprint)
prompt>ssh-keygen -l
Enter file in which the key is (/home/cmic/.ssh/id_rsa):
1024 e5:91:e7:8b:08:d1:ea:de:00:fc:31:26:d0:a0:f9:31 /home/cmic/.ssh/id_rsa.pub
Génération de bubble table digest
prompt>ssh-keygen -B
Enter file in which the key is (/home/cmic/.ssh/id_rsa):
1024 xehil-refyr-zoreg-zakoh-hepyh-pipeb-netyn-bahur-dogid-loloc-laxix /home/cmic/.ssh/id_rsa.pub
Configuration des algo et test de OpenSSH?
- https://linuxfr.org/news/openssh-configuration-des-algorithmes-de-cryptographie
+Port forwarding
What I found on a stackexchange forum (a sketch is worth a thousand words). Here is a link to the forum topic: http://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot. There was two superb sketches:
2016-11-21 09:21:33 -- Cmic
+SSH tunneling thru http proxy
- Sur macinterne compiler corkscrew
- Sur macexterne (tcp/ip # 123.123.123.123), lancer un sshd sur le port 443.
- Sur mactexterne, prévoir de maintenir la connexion ouverte (Parametres ClientAliveInterval? et ClientAliveMax? dans /etc/sshd_config)
- Sur macinterne, dans ~/.ssh/config. Adresse proxy http interne: 172.21.16.1
host macexterne
ProxyCommand? /home/cmic/bin/corkscrew 172.21.16.1 8080 123.123.123.123 443
- puis lancer la connexion :
cmic@macinterne>ssh -R 2222:localhost:22 macexterne
cmic@macexterne's password: ****
...
cmic@macexterne>
- utiliser le tunnel depuis macexterne :
cmic@macexterne>ssh localhost -p 2222
cmic@macinterne's password: ******
cmic@macinterne>
....
cmic@macinterne>exit
cmic@macexterne>
+SSH reverse tunneling
On veut accéder en SSH a un PC connecté en Wifi. depuis une client Linux IP 138.47.99.99
Destination en WiFi? (192.168.20.55) <- Source Linux (138.47.99.99)
1. On lance une session SSH depuis la destination vers la source :
prompt_destination> ssh -R 19999:localhost:22 sourceuser@138.47.99.99 # port 19999 ou autre port > 1024.
2. Depuis le poste source, on accède au PC destination a travers le tunnel SSH :
prompt_source> ssh localhost -p 19999
+Utilisation de SSH agent
- generer un jeu de clefs avec ssh-keygen et la protéger avec un mot de passe
- copier la clef publique sur la machine distante
prompt>cat ./ssh/id_rsa.pub | ssh user@machineA 'cat - >> /home/user/.ssh/authorized_keys
3.lancer l'agent (une socket va être créee a l'écoute de ssh et les variables d'environnement SSH_AUTH_SOCK et SSH_AGENT_PID vont être crées)
prompt>eval 'ssh-agent'
4.ajouter la clef privée à ssh-agent
prompt>ssh-add
5.se connecter a machineA sans taper le mot de passe de la clef privée... Eventuellement, arreter ssh-agent en faisant ssh-agent -k
+SSH thru port knocking
Not tested
$IPT -N stage1
$IPT -A stage1 -m recent --remove --name knock
$IPT -A stage1 -p tcp --dport 3456 -m recent --set --name knock2
$IPT -N stage2
$IPT -A stage2 -m recent --remove --name knock2
$IPT -A stage2 -p tcp --dport 2345 -m recent --set --name heaven
$IPT -N door
$IPT -A door -m recent --rcheck --seconds 5 --name knock2 -j stage2
$IPT -A door -m recent --rcheck --seconds 5 --name knock -j stage1
$IPT -A door -p tcp --dport 1234 -m recent --set --name knock
$IPT -A INPUT -m --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A INPUT -p tcp --dport 22 -m recent --rcheck --seconds 5 --name heaven -j ACCEPT
$IPT -A INPUT -p tcp --syn -j doo
+Stop SSH brute force logins w iptables
Insert these 2 rules :
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP
- The first rule sets a counter for NEW connections to port 22
- the second rule updates the "circular" counter for a maximum count of 4 attempts during 60 seconds. Otherwise, the connection is dropped.
+Stop SSH brute force logins w sshgards
Installer sshguard http://www.sshguard.net/; . Blocage de ssh si nb d'accès trop important par unité de temps. Possibilite de whiteliste.
Testé OK sur FreeBSD? 9.0.
+Stop SSH brute force (and DNS brute force) logins w phrel
Use this C script under Linux. Requires iptables, SNMP, .. http://www.digitalgenesis.com/software/phrel/
+Utilisation de sshfs (au lieu de NFS)
- installer ssfs
- le serveur nacre partage /usr/public
- sur la machine stack:
prompt-cmic>sshfs nacre:/usr/public /mnt -o idmap=cmic
idmap mappe le user id du serveur vers le client.
+ssh proxy
prompt-cmic>ssh -D 8890 cmic@nico.be
Ensuite, utiliser le proxy SOCKS (SOCKS V5) de Firefox avec proxy:localhost, port: 8890.
Toujours dans Firefox, dans about:config :
network.proxy.socks_remote_dns user set boolean true
+Utilisation de ~/.ssh/config
Au lieu de la ligne de commande :
prompt-cmic>ssh -p12345 cmic@nacre.net -i ~/.ssh/clef-privee
Mettre ceci dans ~/.ssh/config :
Host nacre
User cmic
Port 12345
IdentityFile? ~/.ssh/clef-privee
HostName? nacre.net
Et ensuite, utiliser ssh :
prompt-cmic>ssh nacre
+Partage de connexions (controlpath) not tested
A placer dans ~/.ssh/config
Host nacre
Controlmaster auto
Controlpath ~/.ssh/ssh-%r@%h:%p.sock
A la premiere connexion, une socket sera cree dans ~/.ssh . Cette socket sera utilisee pour tout commande ssh (scp, sfcp, rsync, ..)
+ssh pour se connecter a travers une autre connexion ssh
- Placer ces lignes dans .ssh/config pour acceder directement a 'host2' qui est situe sur un reseau prive uniquement disponible depuis 'host1'. NB: -T disable tty allocation). Utilisation de netcat.
Host host2
ProxyCommand? ssh -T host1 'nc %h %p'
HostName? host2
- Autre utilisation : J'ai acces a hostA, mais pas a hostB ; mais hostB a ma clef publique, et hostA peut acceder a hostB. On peut alors par exemple copier vers hostB a travers hostA en faisant :
prompt-hostC> tar -c /rep/fichiers | ssh -A user@hostA "ssh -A user@hostB tar xf -"
NB: -A Enables forwarding of the authentication agent connection.
+rsync and ssh
+SSH on another ports
|