Create SSH keys for Login » History » Version 7
Timo Eronen, 2016-05-04 08:21
| 1 | 1 | Timo Eronen | h1. Create SSH keys for Login |
|---|---|---|---|
| 2 | |||
| 3 | As an example we create keys for *titan* cluster. |
||
| 4 | |||
| 5 | 3 | Timo Eronen | Login to the computer from which you want to access the Cluster and change into directory *~/.ssh/* |
| 6 | 1 | Timo Eronen | |
| 7 | <pre> |
||
| 8 | cd ~/.ssh/ |
||
| 9 | </pre> |
||
| 10 | |||
| 11 | If you don't have such directory, create it and change into it. |
||
| 12 | |||
| 13 | Create key pair using the following command. |
||
| 14 | |||
| 15 | *DO NOT SETUP PASSPHRASE !!* |
||
| 16 | |||
| 17 | <pre> |
||
| 18 | ssh-keygen -f id_rsa_titan -t rsa |
||
| 19 | </pre> |
||
| 20 | |||
| 21 | 2 | Timo Eronen | Now you have key pair: |
| 22 | 1 | Timo Eronen | |
| 23 | * *id_rsa_titan* is your private key. *Keep it secret*. |
||
| 24 | * *id_rsa_titan.pub* is your public key. |
||
| 25 | 2 | Timo Eronen | |
| 26 | Make sure the private key has the right protection: |
||
| 27 | |||
| 28 | <pre> |
||
| 29 | chmod 400 id_rsa_titan |
||
| 30 | </pre> |
||
| 31 | |||
| 32 | 1 | Timo Eronen | |
| 33 | Send the public key (id_rsa_titan.pub) to the Cluster: |
||
| 34 | |||
| 35 | *DO NOT SEND FILE id_rsa_titan WHICH IS YOUR PRIVATE KEY AND SHOULD BE KEPT SECRET.* |
||
| 36 | |||
| 37 | <pre> |
||
| 38 | scp id_rsa_titan.pub titan.utu.fi: |
||
| 39 | </pre> |
||
| 40 | |||
| 41 | Login into titan.utu.fi and while logged change into directory *~/.ssh* |
||
| 42 | |||
| 43 | <pre> |
||
| 44 | 5 | Timo Eronen | ssh titan.utu.fi |
| 45 | 1 | Timo Eronen | cd ~/.ssh/ |
| 46 | </pre> |
||
| 47 | |||
| 48 | 7 | Timo Eronen | Depending on whether you already have file named *authorized_keys* continue with either *Option A* or *Option B*. |
| 49 | 1 | Timo Eronen | |
| 50 | 6 | Timo Eronen | *Option A*) If you have file named *authorized_keys* add contents of id_rsa_titan.pub at the end of *authorized_keys* |
| 51 | |||
| 52 | 1 | Timo Eronen | <pre> |
| 53 | cat ../id_rsa_titan.pub >> ./authorized_keys |
||
| 54 | </pre> |
||
| 55 | |||
| 56 | 6 | Timo Eronen | Now you can get rid of file ../id_rsa_titan.pub |
| 57 | |||
| 58 | <pre> |
||
| 59 | rm ../id_rsa_titan.pub |
||
| 60 | </pre> |
||
| 61 | |||
| 62 | *Option B*) If you don't have file named *authorized_keys* rename id_rsa_titan.pub to *authorized_keys* and move it: |
||
| 63 | 1 | Timo Eronen | |
| 64 | <pre> |
||
| 65 | mv ../id_rsa_titan.pub ./authorized_keys |
||
| 66 | </pre> |
||
| 67 | |||
| 68 | Logout from titan.utu.fi |
||
| 69 | |||
| 70 | Edit your local config file ... |
||
| 71 | |||
| 72 | <pre> |
||
| 73 | emacs config |
||
| 74 | </pre> |
||
| 75 | |||
| 76 | ... and add the following lines: |
||
| 77 | |||
| 78 | <pre> |
||
| 79 | Host titan |
||
| 80 | User YOUR_USERID |
||
| 81 | HostName titan.utu.fi |
||
| 82 | IdentityFile ~/.ssh/id_rsa_titan |
||
| 83 | </pre> |
||
| 84 | |||
| 85 | Replace YOUR_USERID with your user id in titan. |
||
| 86 | |||
| 87 | You setup is done now and you should be able to login: |
||
| 88 | |||
| 89 | <pre> |
||
| 90 | ssh titan |
||
| 91 | </pre> |