ssh-copy-id

To use the ssh-copy-id command effectively, follow the steps below. This command allows you to copy your SSH public key to a remote server, enabling passwordless login via SSH.


Prerequisites

  1. SSH Key Pair: Make sure you have an SSH key pair generated. The default location is:

    • Public key: ~/.ssh/id_rsa.pub
    • Private key: ~/.ssh/id_rsa

    If you don't have an SSH key, generate one with the following command:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    

    Just hit Enter for all prompts to use the default location and settings.

  2. Remote Server Access: You need to have SSH access to the remote server using a password at least once to copy the key.


Steps to Use ssh-copy-id

1. Copy the Public Key to the Remote Server

Use the following command to copy your public key to the remote server:

ssh-copy-id user@remote-server-ip

Replace:

  • user: Your username on the remote server.
  • remote-server-ip: The IP address or hostname of the remote server.

Example:

ssh-copy-id john@192.168.1.10

2. Provide the Password

When prompted, enter the password for the user on the remote server. The ssh-copy-id command will:

  • Append your public key to the ~/.ssh/authorized_keys file on the remote server.
  • Set the correct permissions on the authorized_keys file and directory.

3. Test Passwordless Login

After the key is copied, try logging into the remote server to verify the setup:

ssh user@remote-server-ip

If everything is configured correctly, you won't be prompted for a password.


Optional: Specify a Custom SSH Key

If you are using a non-default SSH key (for example, ~/.ssh/my_custom_key), you can specify it with the -i option:

ssh-copy-id -i ~/.ssh/my_custom_key.pub user@remote-server-ip

Common Issues and Solutions

  • Permission Denied (Public Key): Ensure that:

    • The ~/.ssh directory on the remote server has 700 permissions.
    • The ~/.ssh/authorized_keys file has 600 permissions.

    You can set the correct permissions manually:

    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    
  • No SSH Key Found: Make sure you generated the SSH key with ssh-keygen and the public key is available at ~/.ssh/id_rsa.pub.


Using ssh-copy-id is a convenient way to set up passwordless SSH access, improving both security and ease of use!

댓글

이 블로그의 인기 게시물

To switch to a specific tag in a Git repository

kafka polling vs listen

Create topic on Kafka with partition count, 카프카 토픽 생성하기

To download a file from MinIO using Spring Boot, 스프링부트 Minio 사용하기

Scan an HBase table with a prefix filter

Joining an additional control plane node to an existing Kubernetes cluster

max_active_runs of Airflow

Vespa vs Milvus

urllib3 with proxy settings

The Consumer.wakeup() method in the Kafka Consumer