All posts by J James

Visual Studio Code – Linux

Are you still relying on the vi or vim editor as a Linux admin when scripting in Bash, Ansible, or Python? It might be worth considering a shift to Visual Studio Code, the widely acclaimed IDE. Visual Studio Code offers a plethora of extensions that can greatly simplify the coding process. Instead of installing Visual Studio Code directly on your Linux development machine, a more efficient approach is to install it on your Windows machine. You can then utilize the Remote-SSH extension to seamlessly connect to any of your development servers.

In this post, I’ll walk you through the process of connecting to your Linux server using the Remote-SSH extension and then demonstrate how you can enhance your Bash coding experience by incorporating the Bash-IDE extension.

Step1:  Download and install Visual Studio Code from Microsoft, and upon completion of the installation, launch the application to access the following screen:

Step 2:  Install the Remote-SSH extension. Access the EXTENSIONS search by pressing CTRL+Shift+X. Look for “Remote-SSH” and proceed to install it.

Step 3: Establish a password-less connection between the PC and the remote Linux host as demonstrated below:

  • On Windows PowerShell, run ssh-keygen.exe with default values to generate the SSH keys. Use scp to copy the public key (id_rsa.pub) to the remote host
  • On the remote Linux system, ensure the existence of the .ssh/authorized_keys file in the user’s home directory. If it doesn’t exist, create it, and then append the contents of id_rsa.pub to it. 
  • Set permissions for the .ssh dir to 700 and for the authorized_keys file to 600

Step 4: Add the remote Linux host to VS Code

  • Access the Command Palette by pressing CTRL + SHIFT + P
  • Execute the command by entering “> Remote SSH: Add New SSH Host”.
  • Enter the SSH command to connect, ex: root@192.168.1.110, if connecting as root.
  • Store the host information in “.ssh/config” under the user’s home directory

Step 5: Connect the remote Linux host from VS Code

  • Access the Command Palette by pressing CTRL + SHIFT + P.
  • Execute the command “> Remote SSH: Connect to Host…” and choose the host from the list. A shortcut is to click on the blue icon in the bottom left corner.

A new window will open upon connecting to the remote Linux host.