70 %
Chris Biscardi

Copy an extra key to a Digital Ocean Droplit

I need to add a key to my pre-existing Digital Ocean Droplit that I can use as a single-purpose key inside of a GitHub Action to ssh into the Droplit.

Create a new key

shell
➜ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/chris/.ssh/id_rsa): /Users/chris/.ssh/corgo-bot_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/chris/.ssh/corgo-bot_rsa.
Your public key has been saved in /Users/chris/.ssh/corgo-bot_rsa.pub.
The key fingerprint is:
SHA256:8hvKaFfL2tYW8Bp+rGA8PRnnTIdm+Zdzzxhj1laXN+s chris@core
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| |
| . o .|
| . SoB . o+|
| . +oXoo o*|
| =+**o.. O.+|
| .+.=*+= +.O.|
| ...+o++ .Eo|
+----[SHA256]-----+

Copy Key to DO

replacing xxx.xx.xx.xx with the ip address of your droplit, we can use scp to upload our newly generated public key.

shell
scp ~/.ssh/corgo-bot_rsa.pub root@xxx.xx.xx.xx:/opt/corgo-bot_rsa.pub

We then also need to add it to the end of the ~/.ssh/authorized_keys file. We can use this by taking advantage of >> which will append output to a file.

shell
ssh root@xxx.xx.xx.xx
cat ~/opt/corgo-bot_rsa.pub >> ~/.ssh/authorized_keys

Test key

Then we can ssh in and test to make sure the key works

ssh -i ~/.ssh/corgo-bot_rsa root@xxx.xx.xxx