- Note: If a step has already been done, it is not necessary to repeat it.
- Open a terminal
- Generate your ssh public/private keypair using ssh-keygen. The program will prompt you for a passphrase. Leaving it blank and pressing enter will simplify the process. Note that it is important you do not share your private key.
$ ssh-keygen -t ed25519 -C "[email protected]"- Copy it to the remote server using ssh-copy-id where
<public_key_filename>.pubis the filename of the public key.
ssh-copy-id -i ~/.ssh/<public_key_filename>.pub <your_username>@<remote_hostname>- Test that the setup by logging in via ssh to the remote server. It should not require a password.
ssh <your_username>@<remote_hostname>-
Start VSCode
-
Install the following VSCode extensions.
- C/C++ Extension by Microsoft
- Remote-SSH Extension by Microsoft
-
Click the Remote Explorer on left hand tool bar.
-
Add a new remote target by clicking on the plus sign.
-
When given the option to
Enter SSH Connection Command, type in the appropriate command and press Enter.ssh <your_username>@<remote_hostname> -
When asked to
Select SSH configuration file to update, select the config file for your user account. Note that/homemay be a much longer path./home/<your_local_username>/.ssh/config -
In a local terminal, verify the config file permissions are set to only be readable by you. The file permissions for the file should be 600 or
-rw-------ls -la /home/<your_local_username>/.ssh/config -
If the file permissions are not 600 or
-rw-------, then you can change them using the following command.chmod 600 /home/<your_local_username>/.ssh/config -
The <remote_hostname> will appear in the
SSH TARGETSlist. Click the small icon at the right of the hostname which looks like a folder with a plus sign on top of it. -
A new VSCode window will open. Confirm it is connected to the remote host by opening a terminal in VSCode using Ctrl+`. You should see a terminal open where the prompt matches that for your <remote_host>.
-
Open VSCode
-
Connect to the
<remote_hostname>server via the remote explorer. -
Create a folder to store your program.
mkdir cremote -
Click
File->Open Folder -
Select the folder you created and click Ok.
-
If prompted with dialogs asking about trust, click the trust buttons. (Assuming you trust yourself and the code you will put in the directories. :)
-
Next to the CREMOTE folder in the VSCode Explorer, Click the New File button. (Note the button may not appear until you hover over the entry for the CREMOTE folder.)
-
Type in the name of your file.
cremote.c -
In the newly created file enter the following simple C code and save the file.
#include <stdio.h>
int main(int argc, char** argv){
printf("Hello Remote World!\n");
return 0;
}-
Immediately to the left of line 6 set a break point by clicking on the dark red dot that appears as you move your cursor to the left of the line number. When set, it should be bright red and stay even after you move your cursor.
-
Click the Debug C/C++ File button.
-
Select the appropriate configuration from the drop down menu. Probably some variation of
gcc. If there is more than one, make sure it matches the architecture of the <remote_hostname> machine. -
Note the output in the TERMINAL and that the program counter has stopped at the line with the breakpoint you set.
-
Enjoy remote coding!