Reputation: 8316
I'm setting up a CD workflow via GitHub Actions and tutorials like this suggest that I have to
~/.ssh/authorized_keys
(or ~/.ssh/authorized_keys2
) and private key to github secret to be used in action (done, note that private key can be only on github as secret, so access is safe)~/.ssh/id_rsa
) and put public key to GH as a deploy keyI wonder if I can modify 3.: can I store both public and private key on GH, and pass private key from a GH secret to bash to do the pull? This way, it'll be tighter security, quicker setup on a new server and even quicker migration/setup of multiple projects.
Haven't found anything on this yet, although I may search using wrong keywords...
Upvotes: 1
Views: 731
Reputation: 1323175
Can I store both public and private key on GH
First, storing the private key alone would be enough: you can generate the public key from the private one.
Second, if you pass a private key, make sure you GH action removes it from the server once said action is completed.
That way, said private key is only used when needed, and does not remain on the server.
Since your GH Action has access through its own SSH key to the server, it can:
key2
' file, as shown herescp
that key2
file to the serverssh
the rm key2
command to remove the file at the completion of the action: ssh -i /path/to/private/key1 'rm /remote/path/to/key2'
.Upvotes: 1