Create SSH keys for Login » History » Version 12
Henrik Levämäki, 2017-02-09 18:36
| 1 | 1 | Timo Eronen | h1. Create SSH keys for Login |
|---|---|---|---|
| 2 | |||
| 3 | As an example we create keys for *titan* cluster. |
||
| 4 | |||
| 5 | 10 | Timo Eronen | h3. 1) Login to (your personal) 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 | 10 | Timo Eronen | h3. 2) Create key pair using the following command. |
| 14 | 1 | Timo Eronen | |
| 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 | 10 | Timo Eronen | h3. 3) Make sure the private key has the right protection: |
| 27 | 2 | Timo Eronen | |
| 28 | <pre> |
||
| 29 | 1 | Timo Eronen | chmod 400 id_rsa_titan |
| 30 | 2 | Timo Eronen | </pre> |
| 31 | 1 | Timo Eronen | |
| 32 | 10 | Timo Eronen | h3. 4) Send the public key (id_rsa_titan.pub) to the Cluster: |
| 33 | 1 | Timo Eronen | |
| 34 | *DO NOT SEND FILE id_rsa_titan WHICH IS YOUR PRIVATE KEY AND SHOULD BE KEPT SECRET.* |
||
| 35 | |||
| 36 | <pre> |
||
| 37 | scp id_rsa_titan.pub titan.utu.fi: |
||
| 38 | </pre> |
||
| 39 | |||
| 40 | 10 | Timo Eronen | h3. 5) Login into titan.utu.fi and while logged change into directory *~/.ssh* |
| 41 | 1 | Timo Eronen | |
| 42 | <pre> |
||
| 43 | 5 | Timo Eronen | ssh titan.utu.fi |
| 44 | 1 | Timo Eronen | cd ~/.ssh/ |
| 45 | </pre> |
||
| 46 | |||
| 47 | 10 | Timo Eronen | h3. 6) Depending on whether you already have file named *authorized_keys* continue with either *Option 6a* or *Option 6b*. |
| 48 | 1 | Timo Eronen | |
| 49 | 10 | Timo Eronen | *Option 6a*) If you have file named *authorized_keys* add contents of id_rsa_titan.pub at the end of *authorized_keys* |
| 50 | 6 | Timo Eronen | |
| 51 | 1 | Timo Eronen | <pre> |
| 52 | cat ../id_rsa_titan.pub >> ./authorized_keys |
||
| 53 | </pre> |
||
| 54 | |||
| 55 | 6 | Timo Eronen | Now you can get rid of file ../id_rsa_titan.pub |
| 56 | |||
| 57 | <pre> |
||
| 58 | 1 | Timo Eronen | rm ../id_rsa_titan.pub |
| 59 | </pre> |
||
| 60 | 6 | Timo Eronen | |
| 61 | 10 | Timo Eronen | *Option 6b*) If you don't have file named *authorized_keys* rename id_rsa_titan.pub to *authorized_keys* and move it: |
| 62 | 1 | Timo Eronen | |
| 63 | <pre> |
||
| 64 | mv ../id_rsa_titan.pub ./authorized_keys |
||
| 65 | </pre> |
||
| 66 | |||
| 67 | 10 | Timo Eronen | h3. 7) Logout from titan.utu.fi |
| 68 | 1 | Timo Eronen | |
| 69 | 12 | Henrik Levämäki | h3. 8) Using your favorite text editor, edit your local config file in your personal computer in directory *~/.ssh* |
| 70 | 1 | Timo Eronen | |
| 71 | <pre> |
||
| 72 | 12 | Henrik Levämäki | "text editor" config |
| 73 | 1 | Timo Eronen | </pre> |
| 74 | |||
| 75 | ... and add the following lines: |
||
| 76 | |||
| 77 | <pre> |
||
| 78 | Host titan |
||
| 79 | User YOUR_USERID |
||
| 80 | HostName titan.utu.fi |
||
| 81 | IdentityFile ~/.ssh/id_rsa_titan |
||
| 82 | </pre> |
||
| 83 | |||
| 84 | Replace YOUR_USERID with your user id in titan. |
||
| 85 | |||
| 86 | 11 | Timo Eronen | You setup is done now and you should be able to login without giving the password: |
| 87 | 1 | Timo Eronen | |
| 88 | <pre> |
||
| 89 | ssh titan |
||
| 90 | </pre> |