-
Notifications
You must be signed in to change notification settings - Fork 8
Key
Add SSH Key to Personal Machine (Linux and Mac only)
In the previous sections, we created an ssh key to access Github from the development server. Now we will create another one using a very similar process to access the development server from your personal machine.
In your home directory, create the .ssh directory. This will be used to store your keys.
mkdir .ssh
Change into your .ssh directory and create a cpc2 directory (short for ee220cpc2.ecn.purdue.edu). This will store your key to connect to the development server.
cd .ssh
mkdir cpc2
Create and edit a config file for ssh. Enter the text exactly as shown. Create and open config file nano config Enter this text (my username for ee220 is 'epberry' for example): Host cpc2 User Hostname ee220cpc2.ecn.purdue.edu PreferredAuthentications publickey IdentityFile ~/.ssh/cpc2/id_rsa Now it's time to create the actual key.
ssh-keygen -t rsa -C "<comment for the key like ee220>"
Where it says "enter the file in which to save the key", type:
/home/<username>/.ssh/cpc2/id_rsa
When prompted for the password, press enter twice.
Now we need to transfer the key to ee220cpc2. This is the key step that is different. It's basically a command line version of copying and pasting your key into Github's website. If you have trouble with the following commands you can always just manually copy and paste your key into the authorized_keys file in the .ssh directory on the development server.
For Linux (You will need to enter your password for this) ssh-copy-id -i ~/.ssh/cpc2/id_rsa.pub @ee220cpc2.ecn.purdue.edu For Mac cat ~/.ssh/cpc2/id_rsa.pub | ssh @ee220cpc2.ecn.purdue.edu "cat >> ~/.ssh/authorized_keys" To test that this worked, the following command will let you log into the machine.
ssh cpc2
You can log out by typing exit. You should now have two keys, one from your machine to the development server, and one from the development server to github. You can use the first one to log into the development server as in the step above and the second one will function behind the scenes when you do things like git push or git pull.
If you have the error "Permission denied", try the following procedures:
1. In your home directory, type
vi .bashrc
2. Open that .bashrc and then create a new alias by typing any_name_you_want="ssh [email protected] -p23432"
3. Save it and then type
source .bashrc
4. You should now ssh to the server just by typing any_name_you_want you created in step 2 and click enter.
©️ 2016 Cam2 Research Group