Code/Linux

[Linux] ssh 비밀번호 없이 접속

이성훈 Ethan 2023. 7. 31. 15:22

Local terminal 에서

> ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/USER/.ssh/id_rsa): # 그대로 enter키
/Users/USER/.ssh/id_rsa already exists.
Overwrite (y/n)? y # Y 입력
Enter passphrase (empty for no passphrase): # 비밀번호를 설정하는건데 비밀번호 없이 접속해야하기 때문에 아무것도 입력하지 말고 enter키
Enter same passphrase again: # 마찬가지로 아무것도 입력하지 않고 enter 키
Your identification has been saved in /Users/USER/.ssh/id_rsa
Your public key has been saved in /Users/USER/.ssh/id_rsa.pub
The key fingerprint is:
____________________________________________________________
The keys randomart image is:
+---[RSA ____]----+
# 문자열 그림
+----[_____]-----+

 

 

생성된 key 를 ssh 서버에 복사

> ssh-copy-id [USER]@[서버 IP]

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/USER/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[USER]@[서버 IP]s password: # 기존 ssh 에서 사용하는 PW 입력

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh '[USER]@[서버 IP]'"
and check to make sure that only the key(s) you wanted were added.

 

이제 None 이 ssh 서버의 접속 PW 가 되었으니

> ssh [USER]@[서버 IP]

# 접속 완료!!