0% ont trouvé ce document utile (0 vote)
59 vues6 pages

TP SSH

Le document décrit l'installation et la configuration du serveur SSH sur un serveur ainsi que l'utilisation du client SSH pour se connecter au serveur. Il contient les étapes pour installer le paquet openssh-server, configurer le fichier sshd_config, générer les clés publiques/privées, ajouter un utilisateur, et enfin se connecter en tant que cet utilisateur via SSH avec authentification par mot de passe.

Transféré par

soukaina
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
59 vues6 pages

TP SSH

Le document décrit l'installation et la configuration du serveur SSH sur un serveur ainsi que l'utilisation du client SSH pour se connecter au serveur. Il contient les étapes pour installer le paquet openssh-server, configurer le fichier sshd_config, générer les clés publiques/privées, ajouter un utilisateur, et enfin se connecter en tant que cet utilisateur via SSH avec authentification par mot de passe.

Transféré par

soukaina
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd

TP SSH

------------------------------------------------------------------------------
--- installation & configurtion du serveur SSH
------------------------------------------------------------------------------

root@serveur:~# apt-get install openssh-server


Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Paquets suggérés :
ssh-askpass rssh molly-guard ufw
Les NOUVEAUX paquets suivants seront installés :
openssh-server
0 mis à jour, 1 nouvellement installés, 0 à enlever et 0 non mis à jour.
Il est nécessaire de prendre 0 o/298 ko dans les archives.
Après cette opération, 786 ko d'espace disque supplémentaires seront utilisés.
Préconfiguration des paquets...
Sélection du paquet openssh-server précédemment désélectionné.
(Lecture de la base de données... 24019 fichiers et répertoires déjà installés.)
Dépaquetage de openssh-server (à partir de .../openssh-server_1%3a5.5p1-
6+squeeze2_i386.deb) ...
Traitement des actions différées (« triggers ») pour « man-db »...
Paramétrage de openssh-server (1:5.5p1-6+squeeze2) ...
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
Restarting OpenBSD Secure Shell server: sshd.

root@serveur:~# ls /etc/ssh/
moduli sshd_config ssh_host_dsa_key.pub ssh_host_rsa_key.pub
ssh_config ssh_host_dsa_key ssh_host_rsa_key

root@serveur:~# cat /etc/ssh/sshd_config


# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for


Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key


KeyRegenerationInterval 3600
ServerKeyBits 768

LPIC-2 / examen LPI 202 / SSH - Atelier - version 0.1 / Hedi MAGROUN 1/6
# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files


IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)


PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with


# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords


#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables


AcceptEnv LANG LC_*

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

# Set this to 'yes' to enable PAM authentication, account processing,


# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,

LPIC-2 / examen LPI 202 / SSH - Atelier - version 0.1 / Hedi MAGROUN 2/6
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
root@serveur:~#

root@serveur:~# file /etc/ssh/ssh_host_*


/etc/ssh/ssh_host_dsa_key: PEM DSA private key
/etc/ssh/ssh_host_dsa_key.pub: ASCII text, with very long lines
/etc/ssh/ssh_host_rsa_key: PEM RSA private key
/etc/ssh/ssh_host_rsa_key.pub: ASCII text, with very long lines

root@serveur:~# cat /etc/ssh/ssh_host_rsa_key


-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAyxKaG+RyPny4qqf7FX8dc5Qf6QZaAW9iJvl/MoN3KhZ0FOuv
tBMyfEHPQL5RY1/CaKCF9nVQ0gE9AnDsGPHBaZg0mR8fI0xhTzxaHm3Qv2VJOlFY
CNWY3bF+MEDjuEfOsT6E0veX7a4rlqSRS8ze5iEMCmABmSlwaO1/HMBqHUu07vIO
vtnTbzqQK8mAwgT3hz2f9CRgNlhxtBGPkU4d/Z+KVwo78V7KdH7SbohnXzS3ylXe
Ir9Yg5gdUOHFtGIhLpLxY8Xp2SUa2sRLrSDI3DlQ3yHHNNh5izYr7MEGtNsMOwIt
Hel6ue1xeAT1PZQV3Rt/W7gsiHG7mD+souG7vwIDAQABAoIBAGEqb261KizYBIwz
gCJTBkaNM4+OKHb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3R7PBRXXvJots
GOFSkpy3RDaZ02n3W+NdEt1qPCC9atpXUdIJcw/A9Y92UZx/FBj612ifWDkBPOej
DiIT49bnw3/dNe+O/a6XqLQU1GuuWp8m5TasanAAOArfaLcBWPO9
-----END RSA PRIVATE KEY-----

root@serveur:~# cat /etc/ssh/ssh_host_rsa_key.pub


ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQDLEpob5HI+fLiqp/sVfx1zlB/pBloBb2Im+X8yg3cqFnQU66+0
EzJ8Qc9AvlFjX8JooIX2dVDSAT0CcOwY8cFpmDSZHx8jTGFPPFoebdC/ZUk6UVgI1ZjdsX4wQOO4R86x
PoTS95ftriuWpJFLzN7mIQwKYAGZKXBo7X8cwGodS7Tu8g6+2dNvOpAryYDCBPeHPZ/0JGA2WHG0EY+R
Th39n4pXCjvxXsp0ftJuiGdfNLfKVd4iv1iDmB1Q4cW0YiEukvFjxenZJRraxEutIMjcOVDfIcc02HmL
NivswQa02ww7Ai0d6Xq57XF4BPU9lBXdG39buCyIcbuYP6yi4bu/ root@serveur
root@serveur:~#

root@serveur:~# useradd -m mehdi


root@serveur:~# passwd mehdi
Entrez le nouveau mot de passe UNIX : LeMotDePasse
Retapez le nouveau mot de passe UNIX : LeMotDePasse
passwd : le mot de passe a été mis à jour avec succès

LPIC-2 / examen LPI 202 / SSH - Atelier - version 0.1 / Hedi MAGROUN 3/6
------------------------------------------------------------------------------
--- utilisation du client SSH
------------------------------------------------------------------------------

hedi@client:~$ ls /etc/ssh/
moduli ssh_config

hedi@client:~$ cat /etc/ssh/ssh_config

# This is the ssh client system-wide configuration file. See


# ssh_config(5) for more information. This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:


# 1. command line options
# 2. user-specific file
# 3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options. For a comprehensive


# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

Host *
# ForwardAgent no
# ForwardX11 no
# ForwardX11Trusted yes
# RhostsRSAAuthentication no
# RSAAuthentication yes
# PasswordAuthentication yes
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no
# GSSAPIKeyExchange no
# GSSAPITrustDNS no
# BatchMode no
# CheckHostIP yes
# AddressFamily any
# ConnectTimeout 0
# StrictHostKeyChecking ask
# IdentityFile ~/.ssh/identity
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# Port 22
# Protocol 2,1
# Cipher 3des
# Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-
cbc,3des-cbc
# MACs hmac-md5,hmac-sha1,[email protected],hmac-ripemd160
# EscapeChar ~
# Tunnel no
# TunnelDevice any:any
# PermitLocalCommand no
# VisualHostKey no
# ProxyCommand ssh -q -W %h:%p gateway.example.com
SendEnv LANG LC_*
HashKnownHosts yes
GSSAPIAuthentication yes

LPIC-2 / examen LPI 202 / SSH - Atelier - version 0.1 / Hedi MAGROUN 4/6
GSSAPIDelegateCredentials no

-----> connexion [email protected] avec authentification par mot de passe

hedi@client:~$ ssh [email protected]


The authenticity of host '192.168.56.101 (192.168.56.101)' can't be established.
RSA key fingerprint is af:08:de:77:44:fe:4b:22:38:15:84:8d:9c:93:83:01.
Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.56.101' (RSA) to the list of known hosts.


[email protected]'s password: LeMotDEPasse
Linux serveur 2.6.32-5-686 #1 SMP Sun Sep 23 09:49:36 UTC 2012 i686
...
mehdi@serveur:~$ hostname
serveur
mehdi@serveur:~$ exit
Connection to 192.168.56.101 closed.
hedi@client:~$

hedi@client:~$ ls .ssh/
known_hosts

hedi@client:~$ file .ssh/known_hosts


.ssh/known_hosts: ASCII text, with very long lines

hedi@client:~$ cat .ssh/known_hosts


|1|Sh/oZpdk8LArj1v/HLEMy41rSZY=|G6WcKZOAQ4THMV2oM4x422IrZwA= ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQDLEpob5HI+fLiqp/sVfx1zlB/pBloBb2Im+X8yg3cqFnQU66+0
EzJ8Qc9AvlFjX8JooIX2dVDSAT0CcOwY8cFpmDSZHx8jTGFPPFoebdC/ZUk6UVgI1ZjdsX4wQOO4R86x
PoTS95ftriuWpJFLzN7mIQwKYAGZKXBo7X8cwGodS7Tu8g6+2dNvOpAryYDCBPeHPZ/0JGA2WHG0EY+R
Th39n4pXCjvxXsp0ftJuiGdfNLfKVd4iv1iDmB1Q4cW0YiEukvFjxenZJRraxEutIMjcOVDfIcc02HmL
NivswQa02ww7Ai0d6Xq57XF4BPU9lBXdG39buCyIcbuYP6yi4bu/
hedi@client:~$

-----> connexion [email protected] avec authentification par clé

hedi@client:~$ ssh-keygen -t rsa


Generating public/private rsa key pair.
Enter file in which to save the key (/home/hedi/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): LaPhraseDePasse
Enter same passphrase again: LaPhraseDePasse
Your identification has been saved in /home/hedi/.ssh/id_rsa.
Your public key has been saved in /home/hedi/.ssh/id_rsa.pub.
The key fingerprint is:
ac:2b:15:4d:a6:4a:9a:e9:aa:d8:e2:84:40:26:5f:7a hedi@client
The key's randomart image is:
+--[ RSA 2048]----+
| |
| o |
|.o . = |
|+. o. o.. |
|. o=E. .S |
|o +.. .. |
|.o .. |
|+.. . . |
|*+. .. |
+-----------------+
hedi@client:~$

LPIC-2 / examen LPI 202 / SSH - Atelier - version 0.1 / Hedi MAGROUN 5/6
hedi@client:~$ ssh-copy-id [email protected]
[email protected]'s password: LeMotDEPasse
Now try logging into the machine, with "ssh '[email protected]'", and check
in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

hedi@client:~$ ssh [email protected]


---> demande de la passphrase : LaPhraseDePasse

Linux serveur 2.6.32-5-686 #1 SMP Sun Sep 23 09:49:36 UTC 2012 i686
...
mehdi@serveur:~$ file ~/.ssh/authorized_keys
/home/mehdi/.ssh/authorized_keys: ASCII text, with very long lines

mehdi@serveur:~$ cat ~/.ssh/authorized_keys


ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQCmEjjfATUXjLEK9shtwCSBIA+CNjPsoFsy5OsNeUzjij
6N7QOg8BW/NXG6gpeKKWPidTlKqlV2NWe5Ywwc19b/nXgJqH1tmMA4FB1Zy6pSwamtkdYdnlAk
bvCL5UmreSz8uZlXhHi8inz4xqLAwQgDeYdZBpU8HenUSIUVwYIJwVu7y/2x5WmWRIJDnuZ3I7
GIXjg8+9+JqVsiQmEUrEqPZFz+F4ilc4O/CU3XAQTCAMiPIccQ3W86F7YqvIYulxxxDWX9yln3
Uthr9xmpJ02Q0buAuzRngnDNOIBHb+AwCl39c6nELtiJ2Bc5KsiRLMsl47W2zHGdf7ROapV7f9
J5 hedi@client

mehdi@serveur:~$ exit
Connection to 192.168.56.101 closed.
hedi@client:~$

LPIC-2 / examen LPI 202 / SSH - Atelier - version 0.1 / Hedi MAGROUN 6/6

Vous aimerez peut-être aussi