The ssh-copy-id
command is a utility that is used to install the public key of an SSH key pair onto a remote server. This command is used to automate the process of setting up passwordless SSH login. It copies the public key to the remote server’s authorized_keys file, which allows the user to log in without having to enter a password.
Overview
The basic syntax of the ssh-copy-id
command is as follows:
ssh-copy-id [options] [user@]hostname
Here, options
are the command options and user@hostname
is the remote server’s username and hostname.
For example, if the remote server’s username is john
and the hostname is example.com
, the command would be:
ssh-copy-id john@example.com
This command will prompt the user for the remote server’s password and copy the public key to the remote server’s authorized_keys file.
Options
The following table lists the available options for the ssh-copy-id
command.
Option | Description |
---|---|
-i | Specifies the identity file (private key) to use for authentication |
-p | Specifies the port number to use for the SSH connection |
-o | Specifies an option to pass to the SSH client |
Troubleshooting Tips
Here are some common issues that may arise when using the ssh-copy-id
command and their solutions:
- Permission denied (publickey): This error occurs when the SSH key pair is not set up correctly. Make sure that the public key is in the correct location and that the private key has the correct permissions.
- No route to host: This error occurs when there is no network connection to the remote server. Check the network connection and make sure that the remote server is accessible.
- Connection timed out: This error occurs when the remote server is not responding. Check the network connection and make sure that the remote server is running.
Notes
- The
ssh-copy-id
command requires that the remote server has an SSH server installed and running. - The user running the
ssh-copy-id
command must have SSH access to the remote server. - The
ssh-copy-id
command only copies the public key to the remote server’s authorized_keys file. The private key must be kept secure on the local machine.