본문 바로가기
Develop/Ubuntu

[vscode/ssh] 원격 서버에 SSH 연결하기 / 비밀번호 입력 없애기 / 자동로그인

by favorcat 2024. 2. 29.
반응형

1. vscode 확장에서 Remote Development 설치

 

Remote Development - Visual Studio Marketplace

Extension for Visual Studio Code - An extension pack that lets you open any folder in a container, on a remote machine, or in WSL and take advantage of VS Code's full feature set.

marketplace.visualstudio.com

2. SSH 연결

(window) ctrl + shift + p / (mac) command + shift + p
단축키로 command palette를 열어서 Remote-SSH: Connect to Host 실행
새 SSH 호스트 추가 -> 계정명@ip:포트번호 (ex. root@1.1.1.1:2020)

3. auth key 발급

로컬 컴퓨터에서 cmd 창에 아래의 명령어를 실행하고 엔터 계속 누르면 키 발급 완료

 ssh-keygen -t rsa -b 4096 -f rsa_m1

cmd를 실행한 현재 디렉토리에 파일이 생성되므로 파일 확인하면 된다.  >> 확인 명령어 (window) dir / (mac) ls
명령어가 아니라 폴더를 직접 열어서 확인 가능
rsa_m1 , rsa_m1.pub 두 개의 파일 생성 확인
pub 파일을 ftp를 통해서 서버 컴퓨터로 전송

4. 서버 컴퓨터에 key 등록

4-1. 명령어로 전송하기
scp -P {포트번호} {로컬 컴퓨터의 pub 파일 경로} {계정명}@{ip}:{서버컴퓨터의 저장경로}

4-2. FTP로 전송하기
FTP 프로그램으로 드래그앤드랍으로 전송하기

5. 서버에 덮어쓰기

서버에 ssh 파일이 없다면,

rm -rf .ssh
mkdir .ssh
chmod 700 .ssh

ssh 파일이 있다면

cat id_rsa.pub >> .ssh/authorized_keys

 

6. vscode에 key 등록

(window) ctrl + shift + p / (mac) command + shift + p
단축키로 command palette를 열어서 Remote-SSH: Open SHH Configuration File 실행
.ssh/config 파일 열고 아래와 같이 수정

Host 1.1.1.1
    HostName 1.1.1.1
    Port 포트번호
    User 계정명
    IdentityFile 로컬컴퓨터의 저장경로

7. 서버 설정

반응형

Comment