This setup is most useful for GNU-Linux users, and it uses a uniquely named private/public key pair created by Openssl. Notice that you have to specify the name and location where you want to store the key. Usually, this is in the user's
These instructions follow a fictitious user named "New User," who creates a new RSA key pair for his project,
myotherproject. He creates a key with an empty passphrase, which some frown upon. Alternatively, you could use a keychain program to store the passphrase, but then you may as well use that same program to store your HTTPS password and skip using SSH altogether.
1. From the terminal, create a RSA key pair.
newuser@mycomputer:~/myotherproject $ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/newuser/.ssh/id_rsa): /home/newuser/.ssh/myotherproject_rsa Enter passphrase (empty for no passphrase): [Enter] Enter same passphrase again: [Enter] Your identification has been saved in /home/newuser/.ssh/myotherproject_rsa. Your public key has been saved in /home/newuser/.ssh/myotherproject_rsa.pub. The key fingerprint is: f7:96:67:8c:02:60:b9:5d:41:f2:80:bd:48:e1:43:f5 newuser@mycomputer The key's randomart image is: +--[ RSA 2048]----+ | o=+.o | | oo..= . | | .*. .E | | ..=.. | | . S . | | o . + | | . = + | | o o | | | +-----------------+
2. Navigate to My Account, for example, from your project's Repository page and upload your key to the server.
3. Make sure your new key is listed in the Current user keys section.
4. First, follow the Setup New Repository directions on your repository page or in Empty Repository Instructions: SSH, stopping before the
git remote add origin ssh://firstname.lastname@example.org/newuser.git step. It should look something like this:
newuser@mycomputer:~$ mkdir myotherproject newuser@mycomputer:~$ cd myotherproject/ newuser@mycomputer:~/myotherproject $ git init Initialized empty Git repository in /home/newuser/myotherproject/.git/ newuser@mycomputer:~/myotherproject$ touch readme.txt newuser@mycomputer:~/myotherproject$ git add readme.txt newuser@mycomputer:~/myotherproject$ git commit -m 'Initializing myotherproject repository' [master (root-commit) 96a11be] Initializing myotherproject repository 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 readme.txt
5. You need to add a new remote location that represents the project. You can name it anything, but do not name it
origin if you already used that name. Using the project name is a good practice.
newuser@mycomputer:~/myotherproject$ git remote add myotherproject ssh://email@example.com/myotherproject.git
Your remote URL should look something like this:
newuser@mycomputer:~/myotherproject$ git remote -v myotherproject ssh://firstname.lastname@example.org/myotherproject.git (fetch) myotherproject ssh://email@example.com/myotherproject.git (push)
6. You should also have an entry like this in your
newuser@mycomputer:~$ vi .git/config [remote "myotherproject"] url = ssh://firstname.lastname@example.org/myotherproject.git fetch = +refs/heads/*:refs/remotes/myotherproject/*
7. Add an entry to your .ssh/config file for each key that you are using. You can have many entries like this in your
newuser@mycomputer:~$ vi /Users/johnpquan/.ssh/config Host email@example.com/myotherproject.git Hostname firstname.lastname@example.org/myotherproject.git User git IdentityFile /home/newuser/.ssh/myotherproject_rsa
8. Now you can push to your remote repository.
newuser@mycomputer:~/myotherproject $ git push -u myotherproject master The authenticity of host 'projects.cs.uaf.edu (22.214.171.124)' can't be established. ECDSA key fingerprint is 8f:54:7b:54:92:39:38:49:1e:1b:aa:4f:0d:a3:3a:0a. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'projects.cs.uaf.edu,126.96.36.199' (ECDSA) to the list of known hosts. Counting objects: 3, done. Writing objects: 100% (3/3), 228 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: Notifying Redmine about changes to this repository : ‘myotherproject’ ... remote: - Fetching changesets for ‘myotherproject’ repository ... [success] remote: remote: Calling additional post-receive hooks... remote: - Executing extra hook 'hooks/post-receive.d/mail_notifications' remote: multimailhook is disabled remote: To ssh://email@example.com/myotherproject.git * [new branch] master -> master Branch master set up to track remote branch master from myotherproject.