A Journey in Learning

Accessing remote servers in VScode

Recently, I was exploring how to access remote file structures using Vscode. I was informed by a colleague of a tool that will allow a programmer to edit files on a remote terminal using the VScode GUI interface. I have provided a writeup on how to install this program on a Linux distro that uses a pem key file for authentication. This should make coding on a remote server much more easier to do.

(Linux Setup)
Step 1: 
    Open VScode
    go into extensions and search "Remote Development"
    Install The extension pack, it will contain multiple tools for SSH access & remote code management
Step 2:  
    Go to VScode Clock on Bottem left Green '><' Symbol
    Click on remote-ssh Remote-SSH open configuration file: Two lines will be seen
    `/home/user/.ssh/config`
    `/etc/ssh/ssh_config`
Step 3: Allow any name for a pem file to be passed.
    Open `/etc/ssh/ssh_config`
    Scroll down to the list of IdentitFile's and add
    `#   IdentityFile ~/.ssh/*`
    The identify file will look like
    #   IdentityFile ~/.ssh/id_rsa
    #   IdentityFile ~/.ssh/id_dsa
    #   IdentityFile ~/.ssh/id_ecdsa
    #   IdentityFile ~/.ssh/id_ed25519
    #   IdentityFile ~/.ssh/*
Step 4: Add your Terminal to SSH into
    Open `/home/user/.ssh/config`
    Add the following
    {
    Host <any name>
    HostName <ip or DNS address>
    User <user>
    IdentityFile ~/.ssh/<your full pem key name>
    }
Step 5: Add your PEM key to the folder at `~/.ssh
    Open files
    Navigate to home
    press Ctrl+H to show hidden files
    navigate to .ssh
    place pem files here
    make sure permissions are set: right click one pem file and click on properties, navigate to permissions and set every other user to no access except owner, owner should be "Read and Write"
    Alternatively navigate to the file in the terminal and enter the following command
        $ chmod 400 /home/<user>/.ssh/<filename>
Step 6:
    Go to VScode Clock on Bottem left Green '><' Symbol
    Click on remote-ssh: connect to host
    click on <name> for host written in `/home/user/.ssh/config`
    Press Control-Shift-E or Alternatively click on Explorer
    Click on Open folder
    a prompt should show with a entry already placed with /home/<user>/
    press OK and access files

windows versionSimilar to above, some items to note

  1. permissions need to be set.
    A. you will need to have the pem files located in C:\Users\<name>\.ssh\nameofpemfile.pe
    B. The only entity that should have permissions is the owner, disable inheritance and and delete the rest.
  2. Vscode may default the target server to be windows, you can bypass this issue by doing the following:
    A. Go into settings.json for vscode
    B. add the following line
"remote.SSH.remotePlatform": {
"remotehostname": "windows" // Or linux, or macOS
}

Once you connect specify the target server’s OS