You can also find this article in my blog web-warrior-toolbox
When you implement server for your dev, staging, production, etc. environments it happens that you have to access each of those servers when you need to config something or check the execution logs. Instead of having to input a password each time you access a server, you can skip that step by following this procedre.
In a Nutshell
- Generate an SSH key pair on the developer PC if one does not already exist (e.g.
~/.ssh/id_ed25519.pub).
1) Copy the public key to the remote server to ~/.ssh/authorized_keys (each user on remote server has a file with this name). The helper command ssh-copy-id can do this automatically and only needs to be installed on the machine from which it is executed (typically the developer PC).
2) when you want to revoke the access you can delete the public key from ~/.ssh/authorized_keys
In detail
Generate a key pair if needed:
ssh-keygen -t ed25519
Typical files:
~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub
Install the public key for a remote user:
ssh-copy-id user@server
This adds the public key to:
/home/alice/.ssh/authorized_keys
- If there is no
ssh-copy-idin dev-pc you can copy the contents of .pub file to~/.ssh/authorized_keyon remote server manually
Note that SSH keys grant access to a specific user account, not to the entire server.
For a server with multiple users:
/home/alice/.ssh/authorized_keys
/home/bob/.ssh/authorized_keys
/home/deploy/.ssh/authorized_keys
If your public key only exists in Alice's file:
ssh alice@my-server # works
ssh bob@my-server # fails
To allow access as multiple users, add the public key to each user's:
~/.ssh/authorized_keys
To revoke access, remove the corresponding line from:
~/.ssh/authorized_keys
on the target account.
🤖Keep growing your apss and always be learning, dev-san 🥷
Top comments (0)