<?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>Juan Benavides &#187; svn</title>
	<atom:link href="http://juanbenavides.info/tag/svn/feed/" rel="self" type="application/rss+xml" />
	<link>http://juanbenavides.info</link>
	<description>Anotaciones de un Geek</description>
	<lastBuildDate>Tue, 25 Oct 2011 05:08:29 +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>Trabajar con SVN+SSH fácil y sin escribir la contraseña</title>
		<link>http://juanbenavides.info/trabajar-con-svnssh-facil-y-sin-escribir-la-contrasena/2008/12/</link>
		<comments>http://juanbenavides.info/trabajar-con-svnssh-facil-y-sin-escribir-la-contrasena/2008/12/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 01:38:27 +0000</pubDate>
		<dc:creator>Juan Benavides</dc:creator>
				<category><![CDATA[Programación]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://juanbenavides.info/?p=102</guid>
		<description><![CDATA[Hasta hace poco no había necesitado trabajar con Subversion, un sistema de control de versiones diseñado para trabajar con grandes proyectos de software. Pero la hora ha llegado y ahora digo: &#8220;¡¿Por que demonios no lo usaba antes?!&#8221;. A lo que vamos. Supondré que el servidor SVN está instalado y que cuentas con acceso SSH [...]]]></description>
			<content:encoded><![CDATA[<p>Hasta hace poco no había necesitado trabajar con <a href="http://es.wikipedia.org/wiki/Subversion">Subversion</a>, un sistema de control de versiones diseñado para trabajar con grandes proyectos de software. Pero la hora ha llegado y ahora digo: <em>&#8220;¡¿Por que demonios no lo usaba antes?!&#8221;</em>.</p>
<p>A lo que vamos. Supondré que el servidor SVN está instalado y que cuentas con acceso SSH a él. Te han dicho que para empezar a trabajar en el proyecto es por medio de SSH (que es un tanto inusual, normalmente se usa el protocolo <em>svn</em> o <em>http</em>) de la siguiente forma:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> checkout <span style="color: #c20cb9; font-weight: bold;">svn</span>+<span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>usuario<span style="color: #000000; font-weight: bold;">@</span>xxx.xxx.xxx.xxx<span style="color: #000000; font-weight: bold;">/</span>ruta<span style="color: #000000; font-weight: bold;">/</span>de<span style="color: #000000; font-weight: bold;">/</span>tu<span style="color: #000000; font-weight: bold;">/</span>proyecto</pre></div></div>

<p>SSH te pedirá tu contraseña y listo. Pero, ¿tenemos que introducir la contraseña cada vez que hacemos un commit, update, add&#8230;? Si, es parte de la fuerte seguridad que ofrece, sin embargo tambien existe una manera de configurar el servidor y el cliente para no tener que hacerlo siempre.</p>
<p>Normalmente el acceso SSH es por el puerto 22 pero si no es el caso, te puedes ahorrar escribir siempre los mismos datos (como el nombre de usuario, el puerto) predefiniendolos en el archivo: <em>~/.ssh/config</em>. Detalles aquí: <a href="http://kimmo.suominen.com/docs/ssh/#config">Getting started with SSH</a>. La ventaja sería la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Conectarse con SSH sin el archivo ~/.ssh/config</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> usuario<span style="color: #000000; font-weight: bold;">@</span>xxx.xxx.xxx.xxx <span style="color: #660033;">-p</span> <span style="color: #000000;">2222</span>
<span style="color: #666666; font-style: italic;"># Conectarse con SSH con ~/.ssh/config</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> xxx.xxx.xxx.xxx
<span style="color: #666666; font-style: italic;"># Conectarse con SSH con ~/.ssh/config y agregando un dominio local a la IP en /etc/hosts</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> mi_servidor
&nbsp;
<span style="color: #666666; font-style: italic;"># En cualquier de los casos, nos pedirá la contraseña despues de introducir el comando.</span></pre></div></div>

<p>Se trata de hacer esto más fácil, ¿no? Si configuras el archivo <em>~/.ssh/config</em>, te evitas escribir siempre el nombre de usuario y el puerto que usas.</p>
<p>Tambien puedes agregar la IP de tu servidor en el archivo <em>/etc/hosts</em> es aún más fácil, por que aquí es donde se pueden dar de alta dominios locales para tu equipo. La <strong>127.0.0.1</strong> está normalmente asignada al dominio <em>localhost</em>, de modo que cuando hacemos <em>ping localhost</em>, el sistema apuntará a 127.0.0.1. Entonces, tu podrías asignarle a tu IP <strong>xxx.xxx.xxx.xxx</strong> al dominio <em>julia</em> y cuando hagas <em>ping Julia</em>, te apuntará a la IP que diste de alta.</p>
<p>Ahora tenemos que crear las claves SSH para no tener que volver a escribir la contraseña, cosa que se vuelve molesto con el tiempo. Esto lo logramos con el siguiente comando:</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 <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_dsa <span style="color: #660033;">-C</span> <span style="color: #ff0000;">&quot;Escribe aquí un comentario sobre la clave.&quot;</span></pre></div></div>

<p>Despues tenemos que envíar es clave al servidor donde se encuentra el proyecto, vía SSH:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</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;">|</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> xxx.xxx.xxx.xxx <span style="color: #ff0000;">&quot;cat - &amp;gt;&amp;gt; ~/.ssh/authorized_keys&quot;</span></pre></div></div>

<p>Lo anterior es una serie de comandos que básicamente, lee el contenido del archivo local <em>~/.ssh/id_dsa.pub</em>, luego ejecuta un comando vía SSH para insertar esa lectura en el archivo del servidor <em>~/.ssh/authorized_keys</em>.</p>
<p>Esto lo puedes hacer manualmente: abres el archivo local, copias el contenido, te conectas al servidor y lo guardas en la ruta especificada. Es lo mismo, solo que lo he hecho en un solo comando :) En ambos casos, para comprobar que esto te ha funcionado, prueba conectarte por SSH:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># &quot;mostro&quot; apunta a 192.168.1.100, usuario, contraseña y puerto estan predefinidos.</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> mostro</pre></div></div>

<p>Si despues de esto te conectas automáticamente a tu servidor sin escribir la contraseña, entonces vas por buen camino y si eres <strong>usuario de Ubuntu</strong>, aquí termina el tutorial para ti. Solo prueba:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> list <span style="color: #c20cb9; font-weight: bold;">svn</span>+<span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>mostro<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>proyecto</pre></div></div>

<p>Te pedirá la contraseña la primera vez y despues dejará de molestar. Si esto no es así, tendrás que hacer algunos pasos extra- Deberás configurar el <strong>ssh-agent</strong>. <span id="more-102"></span></p>
<p>Si usas <strong>Linux</strong> (una distro antigua), tendrás que editar <em>~/.profile</em> para agregar el siguiente código:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SSH_ENV</span>=<span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>environment
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> start_agent <span style="color: #7a0874; font-weight: bold;">&#123;</span>
     <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Initialising new SSH agent...&quot;</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: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^echo/#echo/'</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #800000;">${SSH_ENV}</span>
     <span style="color: #7a0874; font-weight: bold;">echo</span> succeeded
     <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> <span style="color: #800000;">${SSH_ENV}</span>
     . <span style="color: #800000;">${SSH_ENV}</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
     <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-add</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Source SSH settings, if applicable</span>
&nbsp;
<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: #ff0000;">&quot;<span style="color: #007800;">${SSH_ENV}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
     . <span style="color: #800000;">${SSH_ENV}</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
     <span style="color: #666666; font-style: italic;">#ps ${SSH_AGENT_PID} doesn’t work under cywgin</span>
     <span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-ef</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #800000;">${SSH_AGENT_PID}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> ssh- agent$ <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
         start_agent;
     <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">else</span>
     start_agent;
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Si utilizas <strong>Mac</strong>, tendrás que editar el archivo <em>~/.login</em> con este código:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">sshAgent</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: #000000; font-weight: bold;">set</span> <span style="color: #007800;">sshAgentArgs</span>=<span style="color: #ff0000;">&quot;-c&quot;</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">tmpFile</span>=~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>ssh-agent-info
&nbsp;
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;">#  Check for existing ssh-agent process</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$tmpFile</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #007800;">$tmpFile</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$?</span>SSH_AGENT_PID <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">this</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-elf</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #800000;">${SSH_AGENT_PID}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #c20cb9; font-weight: bold;">ssh-agent</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<span style="color: #000000; font-weight: bold;">`</span>
      <span style="color: #666666; font-style: italic;"># start ssh-agent if status is nonzero</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #660033;">-x</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sshAgent</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">$sshAgent</span> <span style="color: #007800;">$sshAgentArgs</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-2</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$tmpFile</span>
        <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #007800;">$tmpFile</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ssh agent started [<span style="color: #007800;">${SSH_AGENT_PID}</span>]&quot;</span>
        <span style="color: #c20cb9; font-weight: bold;">ssh-add</span>
      endif
    endif</pre></div></div>

<p>Ambos scripts, los he encontrado en <a href="http://stormsilver.net/wordpress/?p=160">Stormsilver: Getting started with SVN+SSH</a> y son pieza clave para lograr el objetivo de éste post, aunque como dije para los usuarios de Ubuntu esto no es necesario, más no se si es igual en otras distribuciones pero es <abbr title="Por prueba y error :D">fácil saberlo</abbr>. Finalmente has:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> list <span style="color: #c20cb9; font-weight: bold;">svn</span>+<span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>mostro<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>proyecto</pre></div></div>

<p>No solo no te pedirá la contraseña, sino que ya no necesitas escribir el usuario, la IP o incluso el puerto, basta con escribir el dominio local para tu servidor en particular, en mi caso <em>mostro</em>&#8230; que en realidad ese servidor <a href="http://www.geepok.com/?p=1038">es un pequeño NSlu2</a> hackeado con <strong>GNU/Linux Unslung</strong> ;)</p>
<p>El resultado es una forma de acceso más fácil de recordar y no tienes que escribir siempre los mismos datos. Ahorras tiempos y te quitas una razón para estresarte :)</p>
]]></content:encoded>
			<wfw:commentRss>http://juanbenavides.info/trabajar-con-svnssh-facil-y-sin-escribir-la-contrasena/2008/12/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

