Copy SSH
Copying your SSH key is a simple and great way to allow for safe ssh communication between your devices.
Create an SSH key
To create an SSH key, you use the ssh-keygen
command. It will be saved at the default /.ssh
location.
ssh-keygen -t rsa -b 4096 -C "Comment here"
Simplest way
The ssh-copy-id
is the simplest way to perform copy of your public SSH key.
ssh-copy-id user@hostname -p <port>
Without password prompt
You can specify the password in the command if you use sshpass
, which you need to install.
sshpass -p server_password ssh-copy-id user@IP -p port_number
Without installing anything
This is a basic command that can be run without installing any third-party applications.
cat ~/.ssh/id_rsa.pub | ssh <user>@<hostname> 'umask 0077; mkdir -p .ssh; cat >> .ssh/authorized_keys && echo "Key copied"'