Create The SSH Key Pair
Create The SSH Key Pair
First, we need to generate a SSH key pair. If you are using Mac or Linux, you can
simply issue the following command in a terminal, but replace the email address with
your own:
ssh-keygen -C "youremail@mailprovider.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/flynn/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in foo_rsa.
Your public key has been saved in foo_rsa.pub.
The key fingerprint is:
ab:cd:ef:01:23:45:67:89:0a:bc:de:f0:12:34:56:78 flynn@en.com
The key's randomart image is:
+--[ RSA 2048]----+
| o+-+ .. |
| E o |
| . ++.o.. |
| o o H . |
| . . = |
| . =o.o= |
| o . |
| . |
| = o . |
+-----------------+
I highly recommend putting a password on the key files, it is one more layer of security
and has a very minimal impact. If you are using Windows based operating system, there
are tools available to generate key pairs, such as PuTTY Gen, though it does come with
a disclaimer that you need to check with your local laws before using it as some
countries have banned it's use. If that isn't the case, you may log into your VPS, create
the key pair, and download both id_rsa and id_rsa.pub for your use.
Next, the VPS will need a user specifically for Git. Most people will simply create a user
called "Git", and that is what we'll do for this tutorial but feel free to name this user
whatever you'd like.
su -
*Some people feel uncomfortable using root in this manner. If your VPS is set up to use
sudo, then do so.
Add the Unix user (not necessarily Git user names) to handle the repositories:
useradd git
Then give your Git user a password:
passwd git
Now it's as easy as:
su git
Now you need to upload your id_rsa.pub file to your Git user's home directory. Once
you have done that, we need let the SSH daemon know what SSH keys to accept. This
is done using the authorized keys file, and it resides in the dot folder "ssh". To create
this, input:
We are going to use the 'cat' command, which will take the contents of a file and return
them to the command line. We then use the '>>' modifier to do something with that
output rather than just print it in your console. Be careful with this, as a single '>' will
overwrite all the contents of the second file you specify. A double '>' will append it, so
make sure you know what you want to do and in most cases it will be easier to just use
">>" so that you can always delete what you append rather than looking to restore what
you mashed over.
Each line in this file is an entry for a key that you wish to have access to this account.
To add the key that you just uploaded, type the following, replacing :
cat ~/.ssh/authorized_keys
If you want to add others to your access list, they simply need to give you their
id_rsa.pub key and you append it to the authorized keys file.
Setup a Local Repository
This is a pretty simple process, you just call the Git command and initialize a bare
repository in whichever directory you'd like. Let's say I want to use "My Project" as the
project title. When creating the folder, I'd use all lower case, replace any spaces with
hyphens, and append ".git" to the name. So "My Project" becomes "my-project.git".
But what if you want a few trusted people to have access to this server and you want to
keep things simple by sorting them by the names of your users? A simple and effective
way to do that is to create a folder named after each person, so in the home folder for
your Git user list, input: