<?xml version='1.0' encoding="UTF-8"?>
<?xml-stylesheet href="/xsl/guide.xsl" type="text/xsl"?>
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">

<guide>
<title>SSH access to cvs.gentoo.org</title>

<author title="Author">
  <mail link="swift"/>
</author>
<author title="Author">
  <mail link="robbat2"/>
</author>
<author title="Editor">
  <mail link="nightmorph"/>
</author>

<abstract>
This mini-guide explains on how to create and use ssh-keys, especially
for use on cvs.gentoo.org.
</abstract>

<version>1.2</version>
<date>2010-04-26</date>

<chapter>
<title>SSH keys</title>
<section>
<title>Creating the SSH keys</title>
<body>

<p>
First of all, be physically logged on to your own computer. Make sure
that no-one will see you typing stuff in, since we are going to type in
passphrases and such. So get your pepperspray and fight all untrusted
entities until you are home alone.
</p>

<p>
Now we are going to create our ssh keys, DSA keys to be exact. Log onto
your computer as the user that you are going to be using when you want
to access cvs.gentoo.org. Then issue <c>ssh-keygen -t dsa</c>:
</p>

<pre caption="Creating SSH keys">
$ <i>ssh-keygen -t dsa</i>
Generating public/private dsa key pair.
Enter file in which to save the key (/home/temp/.ssh/id_dsa): <comment>(Press enter)</comment>
Created directory '/home/temp/.ssh'.
Enter passphrase (empty for no passphrase): <comment>(Enter your passphrase)</comment>
Enter same passphrase again: <comment>(Enter your passphrase again)</comment>
Your identification has been saved in /home/temp/.ssh/id_dsa.
Your public key has been saved in /home/temp/.ssh/id_dsa.pub.
The key fingerprint is:
85:35:81:a0:87:56:78:a2:da:53:6c:63:32:d1:34:48 temp@Niandra
</pre>

<note>
Please be sure to set a strong passphrase on your private key.  Ideally,
this passphrase should be at least 8 characters and contain a mixture of
letters, numbers and symbols.
</note>

<p>
Now wasn't that easy? Let's see what we have created:
</p>

<pre caption="Created files">
# <i>ls ~/.ssh</i>
id_dsa  id_dsa.pub
</pre>

<p>
You'll probably have more files than this, but the 2 files listed above
are the ones that are really important.
</p>

<p>
The first file, <path>id_dsa</path>, is your <e>private</e> key. Don't
distribute this amongst all people unless you want to get into a fight
with drobbins (no, you don't want that). 
</p>

<warn>
If you have several (<e>trusted!</e>) hosts from which you want to 
connect to cvs.gentoo.org, you should copy <path>id_dsa</path> to the
<path>~/.ssh</path> directories on those hosts.
</warn>

<p>
The second file, <path>id_dsa.pub</path>, is your <e>public</e> key.
Distribute this file amongst all hosts that you want to be able to
access through SSH pubkey authentification. This file should be appended
to <path>~/.ssh/authorized_keys</path> on those remote hosts. Also add it
to your local host so you can connect to that one too if you have several
boxes.
</p>

<pre caption="Adding the SSH key to the box">
$ <i>cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys</i>
</pre>

</body>
</section>
<section>
<title>
  Installing your public key on a machine using LDAP authentication for SSH
</title>
<body>

<note>
If you are a new developer, your recruiter will put your first SSH key into
LDAP, so that you can login. You can then add any additional SSH keys yourself
using the following procedure.
</note>

<p>
For most of the Gentoo infrastructure, we use LDAP to distribute user
information including SSH public keys. On these machines,
<path>~/.ssh/authorized_keys</path> should generally not contain your key.
</p>

<p>
Instead, you should place your public key into LDAP, using
<path>perl_ldap</path>, or <path>ldapmodify</path> directly.
The Infrastructure <uri link="/proj/en/infrastructure/ldap.xml">LDAP
guide</uri> describes this in more detail.
</p>

<pre caption="Adding the SSH key with perl_ldap on dev.gentoo.org">
$ <i>perl_ldap -b user -C sshPublicKey "$(cat ~/.ssh/id_dsa.pub)" &lt;username&gt;</i>
</pre>

<warn>
Each <path>sshPublicKey</path> attribute must contain exactly one public key. If you have multiple public keys, you must have multiple attributes!
</warn>

</body>
</section>
<section>
<title>Using keychain</title>
<body>

<p>
Every time you want to log on to a remote host using SSH public key
authentification, you will be asked to enter your passphrase. As much as
everybody likes typing, too much is sometimes too much. Luckily, there is
<c>keychain</c> to the rescue. There is an document on this one <uri
link="/doc/en/keychain-guide.xml">here</uri>, but I'll give you a quick
introduction.
</p>

<p>
First, install <c>keychain</c>:
</p>

<pre caption="Installing keychain">
# <i>emerge keychain</i>
</pre>

<p>
Now have keychain load up your private ssh key when you log on to your local
box. To do so, add the following to <path>~/.bash_profile</path>.  Again, this
should be done on your <e>local</e> machine where you work at the Gentoo CVS.
</p>

<pre caption="Add this to .bash_profile">
keychain ~/.ssh/id_dsa
. .keychain/<comment>hostname</comment>-sh
</pre>

<p>
Be sure to substitute <c>hostname</c> with your hostname.
</p>

</body>
</section>
</chapter>
</guide>
