Skip to content

Instantly share code, notes, and snippets.

@BuiHoangTu
Last active April 13, 2024 10:50
Show Gist options
  • Select an option

  • Save BuiHoangTu/3f8e2f3c5860cde3fced6b5e773ae141 to your computer and use it in GitHub Desktop.

Select an option

Save BuiHoangTu/3f8e2f3c5860cde3fced6b5e773ae141 to your computer and use it in GitHub Desktop.
Hướng dẫn ssh đến server và dùng vscode trên server

Hướng dẫn ssh đến server và dùng vscode trên server

SSH qua terminal đến server

Requirements

Chạy được các câu lệnh sau trên terminal (tìm kiếm cài ssh nếu cần)

  1. ssh
  2. ssh-keygen
  3. ssh-copy-id

Thêm ssh-key vào server

Lợi ích

  1. Không cần username, password khi đăng nhập lần sau
  2. Connection ổn định hơn

Các bước

  1. tạo ssh-key nếu chưa có

    ssh-keygen
  2. thêm ssh-key của máy vào server

    ssh-copy-id -p ${YOUR_PORT} ${YOUR_UNAME}@${YOUR_HOST}
    
    1. thay phần ${X} thành các thông tin của bạn
    2. Nhập password nếu cần
  3. Thử đăng nhập

    ssh -p ${YOUR_PORT} ${YOUR_UNAME}@${YOUR_HOST}

    Nếu server không hỏi password nữa thì bạn đã thành công

Sử dụng vscode qua ssh

Requirements

  1. Visual Studio Code
  2. Plugin Remote - SSH of vscode

Kết nối đến server

  1. Nhấn tổ hợp Ctrl + Shift + p
  2. Gõ vào ô thoại dòng sau: Remote-SSH: Connect to Host
    1. Nếu chưa có kết nối mong muốn, chọn Add new Host
    2. gõ vào ô thoại ssh -p ${YOUR_PORT} ${YOUR_UNAME}@${YOUR_HOST}
    3. Nhấn enter đến hết
    4. Thực hiện lại từ đầu, bạn sẽ thấy ${YOUR_HOST} đã được thêm vào
  3. Chọn Connection muốn kết nối
  4. Giờ bạn có thể dùng vscode như bình thường
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment