<?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>Mads N. Vestergaard</title>
	<atom:link href="http://timmy.dk/feed/" rel="self" type="application/rss+xml" />
	<link>http://timmy.dk</link>
	<description>Software Developer and System Administrator</description>
	<lastBuildDate>Wed, 07 Sep 2011 17:56:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Generer nye SSH Certifikater let</title>
		<link>http://timmy.dk/generer-nye-ssh-certifikater-let/</link>
		<comments>http://timmy.dk/generer-nye-ssh-certifikater-let/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 17:52:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ikke kategoriseret]]></category>
		<category><![CDATA[certifikat]]></category>
		<category><![CDATA[nøgle]]></category>
		<category><![CDATA[sikkerhed]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://timmy.dk/?p=23</guid>
		<description><![CDATA[Jeg oplever til tider at jeg skal have lavet et SSH certifikat, så jeg kan benytte dette til login, fremfor at benytte min kode hvergang. Af sikkerhedsmæssige årsager, ønsker jeg at have et seperat certifikat pr. server, og jeg har derfor lavet nedenstående lille script, der generer et SSH certifikat, og automatisk lægger det op [...]]]></description>
			<content:encoded><![CDATA[<p>Jeg oplever til tider at jeg skal have lavet et SSH certifikat, så jeg kan benytte dette til login, fremfor at benytte min kode hvergang.</p>
<p>Af sikkerhedsmæssige årsager, ønsker jeg at have et seperat certifikat pr. server, og jeg har derfor lavet nedenstående lille script, der generer et SSH certifikat, og automatisk lægger det op på en server, samtidig med at den skriver detaljerne ind I din SSH konfiguration.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #c20cb9; font-weight: bold;">clear</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;Please enter hostname: &quot;</span> <span style="color: #c20cb9; font-weight: bold;">hostname</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$hostname</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Hostname can not be left empty&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;Please enter alias (Default: <span style="color: #007800;">$hostname</span>): &quot;</span> <span style="color: #7a0874; font-weight: bold;">alias</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$alias</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">alias</span>=<span style="color: #007800;">$hostname</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;Please enter username (Default: <span style="color: #780078;">`eval whoami`</span>): &quot;</span> username
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$username</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">username</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #c20cb9; font-weight: bold;">whoami</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;Please enter port (Defaults to 22): &quot;</span> port
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$port</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">port</span>=<span style="color: #ff0000;">&quot;22&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;We are adding <span style="color: #007800;">$hostname</span> with the alias <span style="color: #007800;">$alias</span>, and the username <span style="color: #007800;">$username</span>, on port <span style="color: #007800;">$port</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please wait while we generate the identity file...&quot;</span>;
<span style="color: #007800;">identity</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.ssh/identity_<span style="color: #007800;">$hostname</span>&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-t</span> rsa <span style="color: #660033;">-b</span> <span style="color: #000000;">2048</span> <span style="color: #660033;">-N</span> <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$identity</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$identity</span>.pub <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #007800;">$username</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$hostname</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$port</span> <span style="color: #ff0000;">&quot;mkdir -m 0700 -p <span style="color: #000099; font-weight: bold;">\
</span>.ssh &amp;&amp; cat - &gt;&gt; .ssh/authorized_keys &amp;&amp; chmod 0600 <span style="color: #000099; font-weight: bold;">\
</span>.ssh/authorized_keys&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Host <span style="color: #000099; font-weight: bold;">\t</span><span style="color: #007800;">$alias</span>
User <span style="color: #000099; font-weight: bold;">\t</span><span style="color: #007800;">$username</span>
Port <span style="color: #000099; font-weight: bold;">\t</span><span style="color: #007800;">$port</span>
HostName <span style="color: #000099; font-weight: bold;">\t</span><span style="color: #007800;">$hostname</span>
IdentityFile <span style="color: #000099; font-weight: bold;">\t</span><span style="color: #007800;">$identity</span>
&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>config
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;
Failed to upload identity file, please correct the error above, and try again.&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timmy.dk/generer-nye-ssh-certifikater-let/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

