serveur:openssh

OpenSSH

root$ urpmi openssh openssh-clients openssh-server
$ ssh-keygen -t dsa
#dsa est libre
#rsa est toujours sous instance de brevet...
$ ssh -vCX user@host
# -v pour verbose
# -C pour compresser et crypter la longueur de la clé...
# -X pour exporter le X11
# emacs -display :0 pour ouvrir sur le serveur d'origine

En mode de sécurité élevé avec Mandriva, le programme msec, le remet à jour, et tu te retrouves à chaque instant avec cette ligne dans /etc/hosts.deny

  #ALL:ALL EXCEPT 127.0.0.1:DENY

Solution éditer le fichier /etc/hosts.allow

# hosts.allow	This file describes the names of the hosts which are
#		allowed to use the local INET services, as decided
#		by the '/usr/sbin/tcpd' server.
#
 
 
sshd:  192.168.000.000/255.255.255.255 : allow

Log

sshd: ALL : twist = echo "%d de %u@%h - %c le `date` " >> /var/ssh/ssh.log

le fichier /etc/ssh/sshd_config

HostName workshop
Port 22
ListenAddress 0.0.0.0
SyslogFacility AUTH
LogLevel INFO
PermitRootLogin no
AllowUsers toto
DenyUsers root
KeepAlive yes
PrintMotd no
PrintLastLog yes
AuthorizedKeysFile .ssh/authorized_keys2
PermitEmptyPasswords no
X11Forwarding yes
Compression yes
BatchMode no
ChallengeResponseAuthentication yes
NoHostAuthenticationForLocalhost yes
PubkeyAuthentication yes

Sur le Serveur

Vérifier que dans le fichier /etc/ssh/sshd_config que vous avez les lignes

  • X11Forwarding yes
  • AllowTcpForwarding yes
  • PermitTunnel yes
  • Compression yes

En Local

Configurer le navigateur pour qu'il passe par un proxy SOCKS (choisissez un port supérieur à 1024, par exemple 9999)

 sous linux : ssh -D 9999 user@host
 sous win : "putty" ajoutez le port source 9999 en dynamique
# Installation de geoip
$ aptitude install geoip-bin geoip-database
# Création d'un script d'identification des pays par rapport à l'IP
$ nano /etc/sshfilter.sh
#!/bin/bash

# country codes to ACCEPT
ALLOW_COUNTRIES="FR"

if [ $# -ne 1 ]; then
  echo "Usage:  `basename $0` <ip>" 1>&2
  exit 0 # return true in case of config issue
fi

COUNTRY=`/usr/bin/geoiplookup $1 | awk -F ": " '{ print $2 }' | awk -F "," '{ print $1 }' | head -n 1`

[[ $COUNTRY = "IP Address not found" || $ALLOW_COUNTRIES =~ $COUNTRY ]] && RESPONSE="ALLOW" || RESPONSE="DENY"

logger "$RESPONSE sshd connection from $1 ($COUNTRY)"

if [ $RESPONSE = "ALLOW" ]
then
  exit 0
else
  exit 1
fi
$ chmod +x /etc/sshfilter.sh
$ nano /etc/hosts.deny
# Ajouter la ligne suivante
sshd: ALL
$ nano /etc/hosts.allow
# Ajouter la ligne suivante
sshd: ALL: aclexec /etc/sshfilter.sh %a
$ service ssh restart
$ tail -f /var/log/user.log
$ tail /var/log/syslog
  • serveur/openssh.txt
  • Dernière modification: 2019/08/18 17:49
  • par Fabwice Bend'j