Copy SSH Key to Remote Server

Share
Copy SSH Key to Remote Server
Photo by Moja Msanii / Unsplash

Generate a public/private key pair and copy the public key to the remote host.

# generate public/private keys
ssh-keygen -b 2048 -t rsa -C "your_username" -f filename

# copy key to remote host
cat ~/.ssh/filename.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"

In /etc/ssh/sshd_config change to following settings.

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
PubkeyAuthentication yes

When done restart the ssh service

sudo systemctl restart sshd

Add the configuration to the ~/.ssh/config file

Host linux
  Hostname 10.0.0.50
  User georg
  IdentityFile ~/.ssh/filename
  Port 22

SSH Port ändern

Change the port in the following file: /etc/ssh/sshd_config

#Port 22
Port 5022
sudo firewall-cmd --add-port=5022/tcp --permanent --zone=public
sudo firewall-cmd --reload

# if using a SELINUX distribtuion you have to change SE as well
sudo semanage port -a -t ssh_port_t -p tcp 5022

sudo systemctl restart sshd