<?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>Amicalement Web - Astuces et Bons plans dans le développement web &#187; perl</title>
	<atom:link href="http://www.amicalement-web.net/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.amicalement-web.net</link>
	<description>Astuces et bons plans d&#039;un web developpeur</description>
	<lastBuildDate>Wed, 04 Jan 2012 14:54:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Tips : Configuration de serveurs</title>
		<link>http://www.amicalement-web.net/tips-configuration-de-serveurs/2009/09/22/</link>
		<comments>http://www.amicalement-web.net/tips-configuration-de-serveurs/2009/09/22/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 08:34:45 +0000</pubDate>
		<dc:creator>Benoit</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tcpdump]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=750</guid>
		<description><![CDATA[Pour bien configurer un serveur, il existe plusieurs façons, chaque administrateur ayant la plupart du temps sa propre conf en fonction de ses habitudes et celles de ses users. Je vous propose ici quelques petits tips à mettre en place sur votre serveur pour voir un peu se qui s&#8217;y passe. Connexion SSH Il est [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/tips_config_serveur.png" alt="Tips : Configuration de serveurs" width="614" height="100" class="alignnone size-full wp-image-640" /></p>
<p>Pour bien configurer un serveur, il existe plusieurs façons, chaque administrateur ayant la plupart du temps sa propre conf en fonction de ses habitudes et celles de ses users.</p>
<p>Je vous propose ici quelques petits tips à mettre en place sur votre serveur pour voir un peu se qui s&#8217;y passe.</p>
<p><span id="more-750"></span></p>
<h3>Connexion SSH</h3>
<p>Il est toujours intéressant de connaître les <strong>connexions ssh</strong> des utilisateurs sur votre serveur, que ce soit pour des statistiques ou tout simplement surveiller les différentes connexions pour par exemple intervenir rapidement en cas d&#8217;intrusion.</p>
<p>Pour cela, il existe un moyen très simple avec l&#8217;utilisation de <strong>sshrc</strong>. Dans le man, il est dit :</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">/etc/ssh/sshrc
Commands in this file are executed by ssh when the user logs in,
just before the user's shell (or command) is started.
See the sshd(8) manual page for more information.</pre></div></div>

<p>Nous allons donc y introduire un petit bout de script qui enverra un mail automatiquement.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">DATE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #ff0000;">&quot;+%d-%m-%Y %H:%M&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">IP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$SSH_CONNECTION</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">REVERSE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dig</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$IP</span> +short<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Message + envoi du mail</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;USER : <span style="color: #007800;">$USER</span>
IP : <span style="color: #007800;">$IP</span>
ReverseDNS : <span style="color: #007800;">$REVERSE</span>
Date : <span style="color: #007800;">$DATE</span>
&nbsp;
&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;[SSH] <span style="color: #007800;">$DATE</span> - Connexion de <span style="color: #007800;">$USER</span>&quot;</span> your_email<span style="color: #000000; font-weight: bold;">@</span>domaine.com</pre></div></div>

<p>A chaque connexion ssh d&#8217;un utilisateur, vous recevrez un mail contenant diverses informations. Je souligne au passage qu&#8217;un <strong>authentification ssh par clef</strong> est toujours plus sûre ;)</p>
<h3>Modifications de fichiers</h3>
<p>Il existe plusieurs applications (plus ou moins performantes) permettant de voir les fichiers modifiés sur votre serveur. Ici, un petit script tout bête qui va vous permette de voir <strong>les modifications effectuées depuis X jours</strong> sur votre serveur dans un ou plusieurs répertoires donnés.</p>
<p>Bien entendu c&#8217;est une surveillance basique, rien de comparable avec un contrôleur d&#8217;intégrité (tripwire par exemple), mais cela peut s&#8217;avérer très pratique, notamment pour retrouver rapidement une erreur faite dans un script après une modification, mais aussi pour vérifier qu&#8217;aucune modification externe n&#8217;est faite sur des fichiers sensibles.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">DATE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #ff0000;">&quot;+%d-%m-%Y %H:%M&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">LAPS</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">INFOS</span>=<span style="color: #ff0000;">&quot;Liste des fichiers modifiés :<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-mtime</span> -<span style="color: #007800;">$LAPS</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-mtime</span> -<span style="color: #007800;">$LAPS</span><span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$i</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">INFOS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$INFOS</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$i</span>&quot;</span>
        <span style="color: #000000; font-weight: bold;">fi</span>;
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$INFOS</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;[MODIF] <span style="color: #007800;">$DATE</span> - Fichiers modifies&quot;</span> your_email<span style="color: #000000; font-weight: bold;">@</span>domaine.com</pre></div></div>

<p><em>N.B : Une vérification est faite pour n&#8217;avoir que les fichiers et non les répertoires + fichiers.</em></p>
<p>Dans l&#8217;instruction <strong>for i in &#8230; ; do</strong> vous pouvez mettre plusieurs répertoire en utilisant <strong>`find /rep/ -mtime -$LAPS`</strong>.</p>
<p>Une fois le script créé, il vous suffit de mettre en place un cron (ici à 23h59 tous les jours) qui le lancera automatiquement et vous avertira par mail des changements.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">59</span> <span style="color: #000000;">23</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>script</pre></div></div>

<h3>Consommation de bande passante</h3>
<p>Savoir qui consomme le plus de bande passante sur un serveur est souvent très intéressant, je vous propose donc ici un petit script qui va vous permettre de recevoir par mail les informations concernant les hôtes qui consomment le plus de bande passante, ici sur les <strong>10000 derniers paquets</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">DATE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #ff0000;">&quot;+%d-%m-%Y %H:%M&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
tcpdump <span style="color: #660033;">-c</span> <span style="color: #000000;">10000</span> <span style="color: #660033;">-ni</span> eth0 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-lane</span> <span style="color: #ff0000;">'END{@keys=sort{$h{$a}  &lt;=&gt; $h{$b}} keys %h;for(reverse(@keys)){printf(&quot;%32s =&gt; %i\n&quot;, $_, $h{$_}) if($h{$_}&gt;100);}} $h{$F[1]}++;'</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;[BP] <span style="color: #007800;">$DATE</span> - Consommation bande passante&quot;</span> your_email<span style="color: #000000; font-weight: bold;">@</span>domaine.com</pre></div></div>

<p>A noter que pour faire plaisir à <a  href="http://blog.devorigin.fr/">Vincent</a>, j&#8217;ai utilisé du perl et non du python ^^</p>
<p>Une fois le script en place, un petit ajout dans le cron et c&#8217;est partit. Vous pouvez le faire tourner autant de fois que vous voulez, cela dépend surtout du traffic de votre serveur, ici 4 fois par jour soit toutes les 6 heures.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">* */6 * * * /path/to/your/script</pre></div></div>

<p>Voilà, si cela vous intéresse, il y aura surement d&#8217;autres tips à venir et surtout n&#8217;hésitez pas à demander si vous cherchez un petit truc particulier ou si vous avez des remarques.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/tips-configuration-de-serveurs/2009/09/22/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
