<?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>Digitivity &#187; public key encryption</title>
	<atom:link href="http://digitivity.org/tag/public-key-encryption/feed" rel="self" type="application/rss+xml" />
	<link>http://digitivity.org</link>
	<description>The Digital Productivity Blog</description>
	<lastBuildDate>Sat, 24 Dec 2011 17:34:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>How to Log in to a Webserver Without a Password Using SSH Public Keys on Ubuntu</title>
		<link>http://digitivity.org/417/how-to-login-server-without-passwordless-using-ssh-public-key-ubuntu</link>
		<comments>http://digitivity.org/417/how-to-login-server-without-passwordless-using-ssh-public-key-ubuntu#comments</comments>
		<pubDate>Fri, 25 Dec 2009 17:13:08 +0000</pubDate>
		<dc:creator>Digitivity</dc:creator>
				<category><![CDATA[Power User]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[passwordless]]></category>
		<category><![CDATA[private key]]></category>
		<category><![CDATA[public key]]></category>
		<category><![CDATA[public key encryption]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://digitivity.org/?p=417</guid>
		<description><![CDATA[<p>Posted in <a href="http://digitivity.org/category/audience/power-user" title="Power User">Power User</a></p>You can avoid the annoyance of typing in your password every time you want to log in to your webserver (or other computer) by using public keys with SSH. What Is SSH? SSH is the Secure Shell protocol, which is a way for two computers to talk to one another without anybody being able to [...]


Related posts:<ol><li><a href='http://digitivity.org/781/dreamhost-server-problems-status-rss' rel='bookmark' title='Permanent Link: Dreamhost Problems Status RSS'>Dreamhost Problems Status RSS</a></li>
<li><a href='http://digitivity.org/964/how-to-manually-add-etc-host-ip-address-in-windows-linux-and-osx' rel='bookmark' title='Permanent Link: How to Manually Add Hosts in Windows, Linux, and OS/X'>How to Manually Add Hosts in Windows, Linux, and OS/X</a></li>
<li><a href='http://digitivity.org/318/ubuntu-karmic-koala-910-is-out' rel='bookmark' title='Permanent Link: Ubuntu Karmic Koala 9.10 Is Out'>Ubuntu Karmic Koala 9.10 Is Out</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>You can avoid the annoyance of typing in your password every time you want to log in to your webserver (or other computer) by using public keys with SSH.</p>
<h2>What Is SSH?</h2>
<p>SSH is the Secure Shell protocol, which is a way for two computers to talk to one another without anybody being able to decode what is being said even if the interloper were able to access the raw network communications between the two computers. This is similar to the way web browsers use SSL (Secure Sockets Layer) to talk with e-commerce and other secure websites.</p>
<p>SSH is mostly used for shell access (typing commands for a remote server to execute) and for authenticating SFTP (Secure FTP), which allows downloading and uploading files to and from remote computers.</p>
<h2>Password Annoyances</h2>
<p>Usually, you&#8217;ll type in a username and password to authenticate yourself to the remote computer. But that gets boring real quick. Often you&#8217;ll be tempted to set an easy password, just to make it easier to type in again and again. Yet that&#8217;ll obviously decrease your security.</p>
<p>Add in the fact that many SSH clients tend to get stuck or boot you out if you don&#8217;t continuously use the connection, and that means plenty of password-retyping.</p>
<h2>Solution: SSH Public Keys</h2>
<p>The answer is SSH public-key based encryption. Public-key based encryption relies on two pieces of information: One, a secret and private key which you keep in a secure location (i.e., your home directory), and the other, a public key which you place anywhere you want to log in to.</p>
<p>The key is actually a long number, but it&#8217;s usually expressed as a series of number and letters when written to your hard drive.</p>
<p>I won&#8217;t go into the details of public/private key encryption here, but let it suffice to say that the remote server, encrypts a some data with your public key. The only way to decrypt that data would be if you had the private key, which your local computer does. After it does the decryption, the remote computer is able to trust that you are really you.</p>
<h2>Passwordless Login</h2>
<p>OK, since the only thing you need to log in to a remote computer is a private key, you don&#8217;t need to enter the password associated with your remote username. Hence, you&#8217;ve achieved passwordless login.</p>
<p>Now, since the private key can be used to log in to any one of your remote accounts, you might want to protect it. You can specify what is called a &#8220;passphrase&#8221; for it at the time your create your private key. That might seem slightly paradoxical, since having to enter a passphrase for your private key instead of a password for your remote server doesn&#8217;t seem like an improvement.</p>
<p>There are ways to have a passphrase, and also not have to enter it in again and again, but that&#8217;ll be the subject of another post. For now, anyway, if your personal computer is secure, and you want things to be easy, just don&#8217;t specify a passphrase.</p>
<h2>Creating a Private Key</h2>
<p>To start using SSH public key encryption, you need to create a private key.</p>
<p>Note: be sure SSH is installed for your operating system. It will usually be installed by default on Ubuntu (and just about any other Linux/Unix based system).</p>
<p>To create a private key, use the ssh-keygen program. Type <tt>ssh-keygen</tt> in a terminal:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">js<span style="color: #000000; font-weight: bold;">@</span>buntu910wd:~$ <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span>
Generating public<span style="color: #000000; font-weight: bold;">/</span>private rsa key pair.
Enter <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #c20cb9; font-weight: bold;">which</span> to save the key <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>js<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa<span style="color: #7a0874; font-weight: bold;">&#41;</span>:</pre></div></div>

<p>When prompted for which file you want to save the key in, just press Enter for the default.</p>
<p>If you want to have passwordless logins, don&#8217;t enter a passphrase when prompted. Just press Enter twice:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Enter passphrase <span style="color: #7a0874; font-weight: bold;">&#40;</span>empty <span style="color: #000000; font-weight: bold;">for</span> no passphrase<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
Enter same passphrase again:</pre></div></div>

<p><tt>ssh-keygen</tt> creates the key and then tells you where it saved it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Your identification has been saved <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>js<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.
Your public key has been saved <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>js<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub.</pre></div></div>

<p>Your public and private keys are saved in a hidden folder called <tt>.ssh</tt> in your home directory. The ssh-keygen program sets permissions to allow only yourself to read the private key, but if you want to be sure, just do an <tt>ls -l</tt>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">js<span style="color: #000000; font-weight: bold;">@</span>buntu910wd:~<span style="color: #000000; font-weight: bold;">/</span>.ssh$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span>
total <span style="color: #000000;">12</span>
<span style="color: #660033;">-rw-------</span> <span style="color: #000000;">1</span> js js <span style="color: #000000;">1675</span> <span style="color: #000000;">2009</span>-<span style="color: #000000;">12</span>-<span style="color: #000000;">25</span> <span style="color: #000000;">16</span>:<span style="color: #000000;">29</span> id_rsa
<span style="color: #660033;">-rw-r--r--</span> <span style="color: #000000;">1</span> js js  <span style="color: #000000;">395</span> <span style="color: #000000;">2009</span>-<span style="color: #000000;">12</span>-<span style="color: #000000;">25</span> <span style="color: #000000;">16</span>:<span style="color: #000000;">29</span> id_rsa.pub
<span style="color: #660033;">-rw-r--r--</span> <span style="color: #000000;">1</span> js js <span style="color: #000000;">2210</span> <span style="color: #000000;">2009</span>-<span style="color: #000000;">11</span>-<span style="color: #000000;">27</span> <span style="color: #000000;">19</span>:07 known_hosts</pre></div></div>

<p>Note: <tt>id_rsa</tt> is the private key. Guard it well. If someone is able to copy that key, he will be able to log in to any of your remote accounts.</p>
<p><tt>id_rsa.pub</tt> is the public key. No one can log in to your remote accounts just by having your public key, but there&#8217;s no reason to spread it around, either.</p>
<h2>Installing the Public Key</h2>
<p>To use your public and private keys, you have to install the public key on each remote server you want to access without a password.</p>
<p>The way that SSH works by default, it looks for public keys in a file called <tt>authorized_keys</tt> in the .ssh directory. The public keys are are just long sequences of text in a single line.</p>
<p>You can have more than one key in an authorized_keys file (for yourself, or to allow others to log on).</p>
<p>If you&#8217;re setting up SSH keys for the first time, you probably won&#8217;t have an authorized_keys file on your remote server. So you can just copy the file that contains the public key to a new file calle authorized_keys:</p>

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

<p>Then upload the authorized_keys file to the remote computer&#8217;s .ssh directory. If you don&#8217;t have a .ssh directory on the remote computer, create one:</p>

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

<p><strong>Important</strong>: Be sure you upload your public key, and <em>not</em> the private key. The public key has a &#8220;.pub&#8221; file extension.</p>
<p>Then, set the permissions on the authorized_keys file to allow only your account access to the file:</p>

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

<h2>Log in Without a Password</h2>
<p>Now go to a terminal and log in to your account:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> johnsmith<span style="color: #000000; font-weight: bold;">@</span>example.com</pre></div></div>

<p>If all goes well, ssh shouldn&#8217;t ask you for your password, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">js<span style="color: #000000; font-weight: bold;">@</span>buntu910wd:~$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> johnsmith<span style="color: #000000; font-weight: bold;">@</span>example.com
johnsmith<span style="color: #000000; font-weight: bold;">@</span>example.com<span style="color: #ff0000;">'s password:</span></pre></div></div>

<p>Since sftp uses the same authentication mechanism as ssh, you can use the sftp program without passwords, as well.</p>
<h2>Summary</h2>
<ol>
<li>Create a private/public key pair with ssh-keygen.</li>
<li>Copy the id_rsa.pub file to authorized_keys.</li>
<li>Upload the authorized_keys file to the .ssh directory in your home folder on the remote server.</li>
<li>Set permissions to only allow your user to access the key files.</li>
</ol>


<p>Related posts:<ol><li><a href='http://digitivity.org/781/dreamhost-server-problems-status-rss' rel='bookmark' title='Permanent Link: Dreamhost Problems Status RSS'>Dreamhost Problems Status RSS</a></li>
<li><a href='http://digitivity.org/964/how-to-manually-add-etc-host-ip-address-in-windows-linux-and-osx' rel='bookmark' title='Permanent Link: How to Manually Add Hosts in Windows, Linux, and OS/X'>How to Manually Add Hosts in Windows, Linux, and OS/X</a></li>
<li><a href='http://digitivity.org/318/ubuntu-karmic-koala-910-is-out' rel='bookmark' title='Permanent Link: Ubuntu Karmic Koala 9.10 Is Out'>Ubuntu Karmic Koala 9.10 Is Out</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://digitivity.org/417/how-to-login-server-without-passwordless-using-ssh-public-key-ubuntu/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: digitivity.org @ 2012-05-23 22:33:48 -->
