Use ssh-copy-id with an OpenSSH Server Listening On a Different Port

Use ssh-copy-id with an OpenSSH Server Listening On a Different Port

To use ssh-copy-id with an OpenSSH server listening on a different port, you will need to specify the port number in the ssh-copy-id command. For example:

refer to‮uttual:‬ri.com
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 2222 user@host

This will copy the public key from the file ~/.ssh/id_rsa.pub to the ~/.ssh/authorized_keys file on the remote host, using port 2222 for the connection.

If you prefer to use a configuration file instead of specifying the port number on the command line, you can create a file ~/.ssh/config with the following contents:

Host example
    HostName host
    Port 2222
    User user

Then you can use the following command to copy the public key:

ssh-copy-id example

This will use the configuration in the ~/.ssh/config file to connect to the remote host using port 2222 and copy the public key to the ~/.ssh/authorized_keys file on the remote host.

You can then use the ssh command to connect to the remote host using the specified port number:

ssh -p 2222 user@host

Alternatively, you can specify the port number in the HostName field in the ~/.ssh/config file, like this:

Host example
    HostName host:2222
    User user

Then you can use the following command to connect to the remote host:

ssh example

This will use the port number specified in the HostName field in the ~/.ssh/config file to connect to the remote host.

Created Time:2017-10-30 14:27:31  Author:lautturi