Red Hat Training

A Red Hat training course is available for RHEL 8

5.4. SSH 키 쌍 생성

이 절차를 사용하여 로컬 시스템에 SSH 키 쌍을 생성하고 생성된 공개 키를 OpenSSH 서버에 복사합니다. 서버가 적절하게 구성된 경우 암호를 제공하지 않고 OpenSSH 서버에 로그인할 수 있습니다.

중요

다음 단계를 root로 완료하면 root 만 키를 사용할 수 있습니다.

절차

  1. SSH 프로토콜의 버전 2에 대한 ECDSA 키 쌍을 생성하려면 다음을 수행합니다.

    $ ssh-keygen -t ecdsa
    Generating public/private ecdsa key pair.
    Enter file in which to save the key (/home/joesec/.ssh/id_ecdsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/joesec/.ssh/id_ecdsa.
    Your public key has been saved in /home/joesec/.ssh/id_ecdsa.pub.
    The key fingerprint is:
    SHA256:Q/x+qms4j7PCQ0qFd09iZEFHA+SqwBKRNaU72oZfaCI joesec@localhost.example.com
    The key's randomart image is:
    +---[ECDSA 256]---+
    |.oo..o=++        |
    |.. o .oo .       |
    |. .. o. o        |
    |....o.+...       |
    |o.oo.o +S .      |
    |.=.+.   .o       |
    |E.*+.  .  . .    |
    |.=..+ +..  o     |
    |  .  oo*+o.      |
    +----[SHA256]-----+

    ssh-keygen -t ed25519 명령을 입력하여 ssh-keygen 명령 또는 Ed25519 키 쌍과 함께 -t rsa 옵션을 사용하여 RSA 키 쌍을 생성할 수도 있습니다.

  2. 공개 키를 원격 머신에 복사하려면 다음을 수행합니다.

    $ ssh-copy-id joesec@ssh-server-example.com
    /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
    joesec@ssh-server-example.com's password:
    ...
    Number of key(s) added: 1
    
    Now try logging into the machine, with: "ssh 'joesec@ssh-server-example.com'" and check to make sure that only the key(s) you wanted were added.

    세션에서 ssh-agent 프로그램을 사용하지 않는 경우 이전 명령은 가장 최근에 수정된 ~/.ssh/id*.pub 공개 키를 아직 설치하지 않은 경우 복사합니다. 다른 공개 키 파일을 지정하거나 ssh-agent 로 메모리에 캐시된 키보다 파일의 키 우선 순위를 지정하려면 ssh-copy-id 명령을 -i 옵션과 함께 사용합니다.

참고

시스템을 다시 설치하고 이전에 생성된 키 쌍을 유지하려면 ~/.ssh/ 디렉터리를 백업합니다. 다시 설치한 후 홈 디렉터리로 복사합니다. root 를 포함하여 시스템의 모든 사용자에 대해 이 작업을 수행할 수 있습니다.

검증

  1. 암호를 제공하지 않고 OpenSSH 서버에 로그인합니다.

    $ ssh joesec@ssh-server-example.com
    Welcome message.
    ...
    Last login: Mon Nov 18 18:28:42 2019 from ::1

추가 리소스

  • ssh-keygen(1)ssh-copy-id(1) 도움말 페이지.