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!

댓글

이 블로그의 인기 게시물

Using the MinIO API via curl

How to split a list into chunks of 100 items in JavaScript, 자바스크립트 리스트 쪼개기

HTML Inline divisions at one row by Tailwind

Boilerplate for typescript server programing

가속도 & 속도

Gradle multi-module project

How to checkout branch of remote git, 깃 리모트 브랜치 체크아웃

CDPEvents in puppeteer

Sparse encoder

Reactjs datetime range picker