The authorized_keys file in SSH specifies the SSH keys that can be used for logging into the user account for which the file is configured. It is a highly important configuration file, as it configures permanent access using SSH keys and needs proper management.
I need to add a public key to the . ssh/authorized_keys file on my server, how do I do this as I already see an key in there and I need to add a second one? You can type !
Make sure when executing Michael Krelin's solution you do the following
cat <your_public_key_file> >> ~/.ssh/authorized_keys
Note that without the double >>
the existing contents of authorized_keys
will be over-written (nuked!) and that may not be desirable.
mkdir -p ~/.ssh/
cat your_key > ~/.ssh/authorized_keys
cat your_key >> ~/.ssh/authorized_keys
There is already a command in the ssh suite to do this automatically for you. I.e log into a remote host and add the public key to that computers authorized_keys file.
ssh-copy-id -i /path/to/key/file [email protected]
If the key you are installing is ~/.ssh/id_rsa
then you can even drop the -i
flag completely.
Much better than manually doing it!
I know I am replying too late but for anyone else who needs this, run following command from your local machine
cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
this has worked perfectly fine. All you need to do is just to replace
with your own user for that particular host
>ssh user@serverip -p portnumber
>sudo bash (if user does not have bash shell else skip this line)
>cd /home/user/.ssh
>echo ssh_rsa...this is the key >> authorized_keys
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With