Étiquette : openssh

22 janvier 2019 /
1. Format SSH2 (exemple complet)
---- BEGIN SSH2 PUBLIC KEY ----

Comment: "rsa-key-20160402"
AAAAB3NzaC1yc2EAAAABJQAAAgEAiL0jjDdFqK/kYThqKt7THrjABTPWvXmB3URI
pGKCP/jZlSuCUP3Oc+IxuFeXSIMvVIYeW2PZAjXQGTn60XzPHr+M0NoGcPAvzZf2
u57aX3YKaL93cZSBHR97H+XhcYdrm7ATwfjMDgfgj7+VTvW4nI46Z+qjxmYifc8u
VELolg1TDHWY789ggcdvy92oGjB0VUgMEywrOP+LS0DgG4dmkoUBWGP9dvYcPZDU
F4q0XY9ZHhvyPWEZ3o2vETTrEJr9QHYwgjmFfJn2VFNnD/4qeDDHOmSlDgEOfQcZ
Im+XUOn9eVsv//dAPSY/yMJXf8d0ZSm+VS29QShMjA4R+7yh5WhsIhouBRno2PpE
VVb37Xwe3V6U3o9UnQ3ADtL75DbrZ5beNWcmKzlJ7jVX5QzHSBAnePbBx/fyeP/f
144xPtJWB3jW/kXjtPyWjpzGndaPQ0WgXkbf8fvIuB3NJTTcZ7PeIKnLaMIzT5XN
CR+xobvdC8J9d6k84/q/laJKF3G8KbRGPNwnoVg1cwWFez+dzqo2ypcTtv/20yAm
z86EvuohZoWrtoWvkZLCoyxdqO93ymEjgHAn2bsIWyOODtXovxAJqPgk3dxM1f9P
AEQwc1bG+Z/Gc1Fd8DncgxyhKSQzLsfWroTnIn8wsnmhPJtaZWNuT5BJa8GhnzX0
9g6nhbk=
---- END SSH2 PUBLIC KEY ----
2. Format OpenSSH (équivalent de l’exemple ci-dessus)
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAiL0jjDdFqK/kYThqKt7THrjABTPWvXmB3URIpGKCP/jZlSuCUP3Oc+IxuFeXSIMvVIYeW2PZAjXQGTn60XzPHr+M0NoGcPAvzZf2u57aX3YKaL93cZSBHR97H+XhcYdrm7ATwfjMDgfgj7+VTvW4nI46Z+qjxmYifc8uVELolg1TDHWY789ggcdvy92oGjB0VUgMEywrOP+LS0DgG4dmkoUBWGP9dvYcPZDUF4q0XY9ZHhvyPWEZ3o2vETTrEJr9QHYwgjmFfJn2VFNnD/4qeDDHOmSlDgEOfQcZIm+XUOn9eVsv//dAPSY/yMJXf8d0ZSm+VS29QShMjA4R+7yh5WhsIhouBRno2PpEVVb37Xwe3V6U3o9UnQ3ADtL75DbrZ5beNWcmKzlJ7jVX5QzHSBAnePbBx/fyeP/f144xPtJWB3jW/kXjtPyWjpzGndaPQ0WgXkbf8fvIuB3NJTTcZ7PeIKnLaMIzT5XNCR+xobvdC8J9d6k84/q/laJKF3G8KbRGPNwnoVg1cwWFez+dzqo2ypcTtv/20yAmz86EvuohZoWrtoWvkZLCoyxdqO93ymEjgHAn2bsIWyOODtXovxAJqPgk3dxM1f9PAEQwc1bG+Z/Gc1Fd8DncgxyhKSQzLsfWroTnIn8wsnmhPJtaZWNuT5BJa8GhnzX09g6nhbk=

Les deux formats sont plutôt similaires.
Pour obtenir une clé au format OpenSSH depuis une clé au format SSH2, il suffit de supprimer la première et dernière ligne  » —- **** SSH2 PUBLIC KEY —-  » et la ligne  » Comment: « .
Puis de retirer les sauts de ligne pour tout mettre sur une seule ligne par clé.
Chaque clefs devra commencer par (à modifier suivant le type de clef) « ssh-rsa ».

3. Convertir une seule clé SSH2 vers OpenSSH
ssh-keygen -i -f clef_ssh2.pub
4. Convertir toutes les clés *.pub d’un répertoire et les afficher
for i in `ls -1 *pub`; do echo "$(ssh-keygen -i -f $i) $i"; done
5. Convertir toutes les clés SSH2 du répertoire et les ajouter directement dans ~/.ssh/authorized_keys
for i in `ls -1 *pub`; do echo "$(ssh-keygen -i -f $i) $i" >> ~/.ssh/authorized_keys; done
25 avril 2016 /

[pastacode lang= »bash » manual= »yum%20-y%20install%20openssh-server » message= »Installation de Openssh » highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »mkdir%20%2Fchroot_sftp » message= »Création du répertoire qui va accueillir le Chroot » highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »ssh%20-V » message= »On s’assure d’avoir une version supérieur à la 4.9″ highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »chown%20root%3Aroot%20%2Fchroot_sftp » message= »On s’assure que root:root est propriétaire » highlight= » » provider= »manual »/]

Le répertoire chrooté doit impérativement appartenir à root (login:groupe).
Pour un autre utilisateur voir l’option « bind » de la commande mount.

[pastacode lang= »bash » manual= »addgroup%20sftpusers » message= »Création du groupe sftpusers » highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »vi%20%2Fetc%2Fssh%2Fsshd_config » message= »Configuration d’Openssh » highlight= » » provider= »manual »/]

Il faut préciser ici, que l’on utilise le serveur sftp interne à OpenSSH.
Nous activons également le chroot sur le répertoire /chroot_sftp pour tous les utilisateurs du groupe sftpusers et nous interdisons, par mesure de sécurité, la redirection X11 ainsi que le tunnel TCP.

On commence par commenter et modifie le paramètre « Subsystem »:

#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp

Puis on met ça juste à la fin du fichier :

 Match Group sftpusers
ChrootDirectory /chroot_sftp
ForceCommand internal-sftp
AllowTCPForwarding no
X11Forwarding no

Le partie « Match » doit absolument se trouver à la fin du fichier comme on peut le voir dans le man de sshd_config.

Dans le paramètre « ChrootDirectory » on peut rajouter %u pour un répertoire portant le nom de l’utilisateur, ou simplement %h pour le répertoire /home de l’utilisateur

Match
Introduces a conditional block. If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the config file, until either another Match line or the end of the file.

[pastacode lang= »bash » manual= »useradd%C2%A0%20–gid%20sftpusers%20–groups%20sftpusers%20-m%20–shell%20%2Fbin%2Ffalse%20-d%20%2Fchroot_sftp%20sftp1″ message= »Création du compte client sftp1″ highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »mkdir%20%2Fchroot_sftp%2Fsftp1%0Achown%20sftp1%3Asftp1%20%2Fchroot_sftp%2Fsftp1%0Achmod%20700%20%2Fchroot_sftp%2Fsftp1″ message= »Création de son répertoire de travail sftp » highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »%2Fetc%2Finit.d%2Fssh%20restart » message= »On relance ssh » highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »systemctl%20restart%20sshd.service » message= »ou » highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »sftp%20sftp1%40localhost » message= »Test de bon fonctionnement » highlight= » » provider= »manual »/]