Server
SSH setup
On the local machine generate ssh keys and copy them to the remote machine
# generate key
ssh-keygen -b 4096
# copy the public key to remote server
cat ~/.ssh/<public_key>.pub | ssh <user>@<remote_server> "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
On the remote server edit /etc/ssh/sshd_config
file and add/uncomment the following:
PermitRootLogin no
PasswordAuthentication no
After that save, exit and run:
sudo systemctl restart ssh
If you cannot connect to the remote server and you are getting some errors you can check why with appending
-vvv
tossh
command
If you named your ssh key something other than id_rsa
you need to specify the private key in ssh
command like this:
ssh <user>@<server> -i ~/.ssh/<private_key>
SSH config file
Create ~/.ssh/config
file, and add the following:
Host my-awesome-remote-server
HostName 192.168.1.1 # IP address
User <user>
IdentityFile ~/.ssh/<private_key>
and after that you can use ssh my-awesome-remote-server