What I Do/자주 찾는 내용

vscode 에서 서버 접속할 때 마다 Enter password for .. 이런다.

1Millisecond 2022. 11. 7. 00:29

 

2가지를 해야한다. 맥북이든 우분투든 방법은 동일하다.

1. 접속하려는 서버에 내 rsa public key를 등록

2. 내 PC에 config 수정하여 접속하려는 서버에 붙을 때 rsa key를 사용하도록 지정(등록)

 

당연히 rsa key를 생성해놨다는 가정으로 아래를 진행한다.

 

1. 접속하려는 서버에 내 rsa public key를 등록

ssh-copy-id 라는 명령어를 사용한다. -i 뒤에는 내 rsa public key의 위치를 지정하면 된다.

ssh-copy-id -i ~/.ssh/id_rsa.pub -p 포트번호 내아이디@서버주소
/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
내아이디@서버주소's password: 

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh -p '포트번호' '내아이디@서버주소'"
and check to make sure that only the key(s) you wanted were added.

"내아이디@서버주소", "포트번호"는 본인에게 맞게 수정하면 됨.

- 내아이디: 서버에서 사용하는 ssh id

- 서버주소: 서버주소

- 포트번호: default 22인데, default가 아니라서 지정이 필요할 경우 -p 옵션을 사용하면 된다.

 

2. 내 PC에 config 수정하여 접속하려는 서버에 붙을 때 rsa key를 사용하도록 지정(등록)

간혹 2번을 안해도 될 때도 있지만 확실히 하려면 해두는게 좋다.

Host 내아이디@서버주소
  HostName 서버주소
  User 내아이디
  Port 포트번호
  IdentityFile ~/.ssh/id_rsa
  UseKeychain yes

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa