<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Actinux &#187; ssh</title>
	<atom:link href="http://www.actinux.org/index.php/tag/ssh/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.actinux.org</link>
	<description>La réponse libre à un monde libre</description>
	<lastBuildDate>Tue, 09 Feb 2010 10:53:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>L&#8217;outil indispensable SSH</title>
		<link>http://www.actinux.org/index.php/2009/06/05/loutil-indispensable-ssh/</link>
		<comments>http://www.actinux.org/index.php/2009/06/05/loutil-indispensable-ssh/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 08:53:52 +0000</pubDate>
		<dc:creator>ati</dc:creator>
				<category><![CDATA[Divers]]></category>
		<category><![CDATA[Tutos]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssh-add]]></category>
		<category><![CDATA[ssh-agent]]></category>

		<guid isPermaLink="false">http://www.actinux.org/?p=83</guid>
		<description><![CDATA[Beaucoup de personnes connaissent au moins de nom SSH. Cet outil cache pourtant certains secrets très pratiques et bien souvent totalement inconnus.
 
Aujourd&#8217;hui, il est courant de multiplier les accès distants sur des machines. Si Telnet et les r-commandes répondaient à ce besoin, le besoin de sécurité les a écartés de la course. SSH permet [...]]]></description>
			<content:encoded><![CDATA[<p>Beaucoup de personnes connaissent au moins de nom SSH. Cet outil cache pourtant certains secrets très pratiques et bien souvent totalement inconnus.<br />
 <span id="more-83"></span></p>
<p>Aujourd&#8217;hui, il est courant de multiplier les accès distants sur des machines. Si Telnet et les r-commandes répondaient à ce besoin, le besoin de sécurité les a écartés de la course. SSH permet donc d&#8217;accéder à une console distante de manière totalement sécurisée. Nous verrons dans ce tutoriel comment utiliser un client SSH mais aussi comment utiliser le SSH-agent pour faciliter le travail de tous les jours en s&#8217;identifiant rapidement.</p>
<p>La plupart du temps openSSH est déjà installé. Si cela n&#8217;est pas le cas il vous suffit de tapper dans une console :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> yum <span style="color: #c20cb9; font-weight: bold;">install</span> openssh openssh-clients</pre></div></div>

<p>ou</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> openssh-client</pre></div></div>

<p>Pour se connecter simplement sur un serveur il vous suffit de tapper :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">login</span><span style="color: #000000; font-weight: bold;">&gt;@&lt;</span>machinedist<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>où <em>login</em> est le nom du compte que vous souhaitez utiliser et <em>machinedist</em> représente l&#8217;adresse IP ou le nom de la machine visée. Lors d&#8217;une premiere connexion, un message décrivant que la machine distante est inconnue vous sera retournée. Ensuite SSH vous demande s&#8217;il doit continuer ou pas. Répondez &#8216;Yes&#8217; pour continuer. Cette étape permet de vérifier que la machine que vous souhaitez contacter et bien celle qui vous répond. Pour cela SSH utilise une empreinte (fingerprint en anglais) correspondant ni plus ni moins à une suite de valeurs héxadécimales. Une fois acceptée, cette empreinte sera ajoutée à votre liste d&#8217;hôtes connus.</p>
<p>L&#8217;étape suivante est l&#8217;authentification. Par défaut, SSH utilise une authentification par mot-de-passe. Ca n&#8217;est pas la seule manière de s&#8217;authentifier. On peut utiliser une paire de clés publique/privée. La première est une clé que vous partagerez et copierez partout où vous souhaiteriez vous connecter (nous y reviendrons un peu plus tard), la seconde est en quelque sorte l&#8217;équivalent de votre nouveau mot-de-passe.</p>
<p>Pour générer une paire de clés, OpenSSH propose un outil. en tapant dans votre console :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span></pre></div></div>

<p>vous pourrez créer simplement une paire. Vous pouvez, grâce à l&#8217;option &#8216;-t&#8217; préciser quel type de clés vous souhaitez. Sachez que SSH1 utilise généralement des clés RSA1, et SSH2 des clés DSA.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> dsa</pre></div></div>

<p>Le générateur va vous demander où sauvegarder les clés et vous demander une passphrase. Cette passphrase n&#8217;améliore en rien la clé ou la sécurité des échanges. Elle permet juste d&#8217;empêcher quelqu&#8217;un qui récupèrerait votre paire de clés de l&#8217;utiliser. C&#8217;est une phrase protégeant la clé. Lorsque le générateur a fini vous obtenez 2 fichiers :</p>
<ul>
<li><strong>id_dsa</strong> ou <strong>id_rsa</strong> : la clé privé</li>
<li><strong>id_dsa.pub</strong> ou <strong>id_rsa.pub</strong> : la clé public</li>
</ul>
<p>Nous allons désormais donner notre clé public à l&#8217;ordinateur distant, celui auquel nous souhaitons nous connecter. Pour ce faire utilisons cette commande :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ssh-copy-id <span style="color: #660033;">-i</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_dsa.pub <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">login</span><span style="color: #000000; font-weight: bold;">&gt;@&lt;</span>machinedist<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Pour utiliser notre clé et ainsi ne pas avoir à rentrer de mot-de-passe, il suffit désormais d&#8217;entrer :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-i</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_dsa <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">login</span><span style="color: #000000; font-weight: bold;">&gt;@&lt;</span>machinedist<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Nous pouvons encore améliorer notre confort par plusieurs procédés. Dans le cas où vous avez protégé votre clé privée par une passphrase, à chaque connexion cette passphrase vous est demandée. Ensuite il peut paraître ennuyeux de devoir tapper l&#8217;emplacement du certificat, le login et le nom de la machine distance (voir son IP&#8230;). Pas de panique, SSH répond à tous vos problèmes <img src='http://www.actinux.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>D&#8217;abord créons un fichier ~/.ssh/config dans lequel nous placerons :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Host <span style="color: #000000; font-weight: bold;">&lt;</span>NomDeConnexion<span style="color: #000000; font-weight: bold;">&gt;</span>
User <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">login</span><span style="color: #000000; font-weight: bold;">&gt;</span>
HostName <span style="color: #000000; font-weight: bold;">&lt;</span>machinedist<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>où <em>NomDeConnexion</em> représente un identifiant aléatoire vous permettant d&#8217;identifier le compte et la machine définient respectivement par <em>login</em> et <em>machinedist</em>.<br />
Ainsi pour se connecter il suffira de tapper :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-i</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_dsa <span style="color: #000000; font-weight: bold;">&lt;</span>NomDeConnexion<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Enfin, laissons SSH gérer nos clés et nous identifier avec la bonne clé. Pour ce faire, il suffit d&#8217;utiliser ssh-agent. Pour l&#8217;utiliser, initialisez votre terminal en le précédent de &laquo;&nbsp;ssh-agent&nbsp;&raquo; comme ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Voici quelques exemples d'initialisation. Adaptez a votre besoin</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh-agent</span> gnome-terminal
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh-agent</span> <span style="color: #c20cb9; font-weight: bold;">zsh</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh-agent</span> <span style="color: #c20cb9; font-weight: bold;">bash</span></pre></div></div>

<p>Une fois le terminal lancé, vous aurez besoin d&#8217;importer votre(vos) clé(s) grâce à :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-add</span></pre></div></div>

<p>ssh-add va ajouter votre clé ~/.ssh/id_rsa à la liste des clés utilisables par ssh-agent. Pour importer une clé supplémentaire il faut juste lui préciser où les trouver comme ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-add</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa_actinux1 ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa_actinux2</pre></div></div>

<p>Dans le cas d&#8217;une protection de clé par passphrase, elle vous sera demandée (une seule fois <img src='http://www.actinux.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ).<br />
Vous pouvez lister à tout moment l&#8217;ensemble des clés contenues dans votre ssh-agent de part la commande :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-add</span> <span style="color: #660033;">-l</span></pre></div></div>

<p>Ensuite plus besoin de préciser le fichier de clé à utiliser pour se connecter :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #000000; font-weight: bold;">&lt;</span>NomDeConnexion<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Pour terminer je vous conseillerez de placer dans votre fichier rc (.zshrc ou .bashrc par exemple) votre ou vos ssh-add et d&#8217;ajouter le ssh-agent sur les raccourcis utiles (le gnome-terminal par exemple). Ainsi la seule étape que vous aurez à passer 1 fois par jour c&#8217;est d&#8217;entrer votre/vos passphrases à l&#8217;ouverture de votre terminal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.actinux.org/index.php/2009/06/05/loutil-indispensable-ssh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
