ssh

Verified: February 2024, performed on macOS; the steps are identical on Linux and similar on Windows.

Client config

In the user's directory, in the subfolder ".ssh", edit/create the file "config":

Host *
    ServerAliveInterval 30
    ServerAliveCountMax 3
    TCPKeepAlive no

Host NAME_USED_FOR_OPENING_CONNECTION
  HostName IP
  Port PORT
  User USERNAME

...

Passwordless login (key-based)

ssh-keygen # if not done before

ssh-copy-id -p 2222 USER@IP

After ssh-copy-id the ssh client authenticates with the key automatically; the password prompt is gone. Key-based login is also the precondition for a smooth VS Code remote workflow below.

Remote editing with VS Code ("Remote – SSH")

Prerequisites: VS Code installed, plus the extension "Remote – SSH" (Extensions tab → search → Install).

Open a terminal inside VS Code via „New Terminal":

New terminal in VS Code

  1. Connect to the server once manually from the terminal, so the host key gets accepted and the folder for editing is prepared:

    ssh -p PORT USERNAME@SERVER

    Create a workspace directory on the server and note its full path:

    mkdir data && cd data && pwd

    Then end the session with exit.

  2. Add the connection to VS Code: Remote Explorer tab → click "+" next to SSH → enter the same ssh command at the prompt:

    Add ssh connection

    Enter the ssh command

    Choose the local ssh config file to update; the first proposal is normally correct.

    Select ssh config file

  3. The new connection appears in the Remote Explorer (refresh if it does not show up); connect with the "→" arrow:

    Connection in Remote Explorer

  4. In the File Explorer tab click „Open Folder" and enter the workspace path noted in step 1:

    Open folder on the server

    If asked whether the authors of the directory are trusted, confirm — on your own server you are the author.

Files can be copied to the server via drag-and-drop, and downloaded via right-click in the File Explorer. On the next start VS Code re-establishes the connection automatically; when switching environments, connect to the folder entry in the Remote Explorer rather than the bare server, otherwise a folder prompt follows.

Reconnect on next start