Web

[MacOS] 맥북 SSH 접속 셋팅하기 (+RSA Key)

chan10 2025. 6. 28. 15:30

SSH Key 생성하기 (Default - ED25519)

macOS 기본 터미널에서 ssh-keygen 명령어로 SSH 키를 생성할 수 있습니다.

기본적으로 ED25519 방식의 SSH 키를 생성합니다. ED25519방식은 RSA 방식에 비해 보안과 성능면에서 우수한 방식입니다.

chan@MacBookPro .ssh % ssh-keygen  
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/chan/.ssh/id_ed25519): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/chan/.ssh/id_ed25519
Your public key has been saved in /Users/chan/.ssh/id_ed25519.pub

// pwd: ~/.ssh | 생성 완료 후
chan@MacBookPro .ssh % ls
id_ed25519	id_ed25519.pub

 

하지만 일부 구형 장비는 ssh-rsa 방식만 지원하기 때문에, 연결 시 다음 오류가 발생할 수 있습니다.

chan@MacBookPro .ssh % ssh chan@172.30.1.1
Unable to negotiate with 172.30.1.1 port 22: no matching host key type found. Their offer: ssh-rsa

 

SSH Key 생성하기 (RSA)

구형 시스템과의 호환을 위해 RSA 키를 별도로 생성해야 합니다. ssh-keygen 명령어에 -t rsa 옵션을 추가하면 RSA 방식의 키를 생성할 수 있습니다.

chan@MacBookPro .ssh % ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/chan/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/chan/.ssh/id_rsa
Your public key has been saved in /Users/chan/.ssh/id_rsa.pub

chan@MacBookPro .ssh % ls
id_rsa		id_rsa.pub

 

RSA 방식의 Key를 생성 후 SSH 접속을 시도했으나 마찬가지로 Key를 찾을 수 없다고 나옵니다.

Key를 생성하기는 했지만 실제 SSH 협상 시 RSA 방식으로 시도를 하지 않기 때문입니다.

Apple은 OpenSSH 8.8부터 ssh-rsa를 기본적으로 비활성화했기 때문에, 구버전 장비와 연결하려면 수동 설정이 필요합니다.

chan@MacBookPro .ssh % ssh chan@172.30.1.1
Unable to negotiate with 172.30.1.1 port 22: no matching host key type found. Their offer: ssh-rsa

 

RSA 방식을 사용하도록 옵션을 설정하는데 두가지 방식으로 사용할 수 있습니다.

1. 일회성 : ssh -o 옵션 사용

[일회성]
% ssh -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa chan@172.30.1.1
chan@172.30.1.1's password: 

접속 가능

 

2. 영구적 : ssh config 파일 작성 (vi or nano 명령어)

[영구적]
% nano ~/.ssh/config
Host *
  HostKeyAlgorithms +ssh-rsa
  PubkeyAcceptedAlgorithms +ssh-rsa
  IdentityFile ~/.ssh/id_rsa

nano 파일 저장 후 나가기
Ctrl + O → 저장 (WriteOut)
누르면 하단에 파일명을 보여줌 → 그냥 Enter 입력
Ctrl + X → 에디터 종료 (Exit)

% ssh chan@172.30.1.1                                                                   
chan@172.30.1.1's password: 

옵션 없이 접속 가능

위와 같이 설정 시 구버전 장비에도 SSH 접속이 가능하게 됩니다.

 

구형 장비가 추가 알고리즘을 요구하면 KexAlgorithms, Ciphers와 같은 옵션을 ~/.ssh/config에 추가해주면 됩니다.

% nano ~/.ssh/config
# 스위치 접속 시 (구)알고리즘 지원 필요
Host *
  HostKeyAlgorithms +ssh-rsa
  PubkeyAcceptedAlgorithms +ssh-rsa
  KexAlgorithms +diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
  Ciphers +aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc
  IdentityFile ~/.ssh/id_rsa