Configure SSH connection#

In most cases, you probably are developing on a remote linux server instead of your own local pc.

Here we will use the Penn State ACI server as an example demonstrating how you should configure SSH connection within vscode.

Step 1: Setup passwordless connection#

To set up passwordless SSH connection to a remote Linux server, you will need to generate a public/private key pair on your local machine and copy the public key to the remote server. Here’s a step-by-step guide to get you started:

  1. Generate the key pair: Open a terminal window on your local machine and run the following command ssh-keygen -t rsa. The command will prompt you to choose a location for the key pair, you can accept the default location by hitting enter, or you can choose to give it a specific name, such as aci_rsa. You will also be asked to provide a passphrase, but for a passwordless connection, you can leave this field empty by hitting enter.

  2. Copy the public key to the remote server: The public key is stored in the file ~/.ssh/id_rsa.pub. To copy the public key to the remote server, use the following command ssh-copy-id username@submit.aci.ics.psu.edu, this will copy the default id_rsa.pub key to the remote server. If you used a different name for the rsa key pair, you can specify it with the -i option like this, ssh-copy-id -i ~/.ssh/aci_rsa username@submit.aci.ics.psu.edu

  1. Generate the key pair:

    1. Download and install PuTTYgen: You can download the PuTTYgen tool from the PuTTY website (https://www.putty.org/).

    2. Start PuTTYgen: Once you have installed PuTTYgen, start the tool from the Start menu or by double-clicking on the PuTTYgen icon.

    3. Generate the key pair: In the PuTTYgen window, click the “Generate” button. The tool will prompt you to move your mouse around the window to generate randomness for the key pair. Once the key pair is generated, you can enter a key passphrase or leave the field empty for a passwordless connection.

    4. Save the key pair: Once you have generated the key pair, you can save the private key by clicking the “Save private key” button and specifying a location for the file. You can also save the public key by copying its contents from the “Public key for pasting into OpenSSH authorized_keys file” text box and saving it to a file.

  2. Copy the public key to the remote server: Open a Command Prompt or PowerShell window and run the following command type "C:\path\to\id_rsa.pub" | ssh user@submit.aci.ics.psu.edu "cat >> ~/.ssh/authorized_keys". Replace C:\path\to\id_rsa.pub with the path to your public key file, user with the username on the remote server. The type command outputs the contents of the public key file, which are then piped to an ssh command that logs in to the remote server, appends the contents of the public key to the authorized_keys file in the .ssh directory of the user’s home directory, and creates the file if it does not exist.

  1. Test the connection: Once the public key is copied to the remote server, you can test the connection by running ssh username@submit.aci.ics.psu.edu. This should connect you to the remote server without asking for a password. If everything is working as expected, you have successfully set up a passwordless SSH connection.

Step 2: Edit ssh config file#

To further save your time typing your user name and the remote server’s host name, we can setup the ssh config file as follows.

  1. Click F1 to open the command palette, and type ssh connect to search for Remote-SSH: Connect to Host, then click

avatar
  1. You will see two choices of Add New SSH Host or Configure SSH Hosts, select the Configure SSH Hosts

avatar
  1. vscode will automatically detect available ssh config files on your system, you should choose your personal one instead of the system config file, and that ssh config file will be opened in vscode. To me that’s /User/xiaoxingcheng/.ssh/config

avatar
  1. Change the User with your username, and the IdentityFile with the generated/uploaded rsa key pair name in the following code snippet. Then, copy and paste it into the opened config file.

Host aci
    HostName submit.aci.ics.psu.edu
    User username
    IdentityFile ~/.ssh/aci_rsa
    ForwardX11Trusted Yes
    ForwardX11 Yes

Step 3: SSH login#

  1. Open vscode

  2. Click F1, type ssh connect and click Remote-SSH: Connect to Host

signed in
  1. Choose aci, which is the Host we defined in previous step.

signed in
  1. You will see an interface similar to this one, and we can use the terminal to perform any command line tasks in the future. If you don’t see the terminal panel, you can use the shortcut ctrl+`, or click View/Terminal in the menu.

signed in