> ## Content Index
> Fetch the complete content index at: https://www.kollr.at/llms.txt
> Use this file to discover other available public pages before exploring further.

# Copy SSH Key to Remote Server
- URL: https://www.kollr.at/copy-ssh-key-to-remote-server/
- Published: 2026-07-02T13:20:58.000Z
- Updated: 2026-07-02T13:40:09.000Z
- Author: Georg Koller
- Tags: CLI, Linux

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

```powershell
# 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.

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

```

When done restart the ssh service

```bash
sudo systemctl restart sshd

```

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

```ini
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

```ini
#Port 22
Port 5022

```

```bash
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

```