{"id":125652,"date":"2023-02-09T03:52:46","date_gmt":"2023-02-09T03:52:46","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=125652"},"modified":"2023-07-19T11:06:07","modified_gmt":"2023-07-19T11:06:07","slug":"raspberry-pi-remote-ssh-vs-code","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-remote-ssh-vs-code\/","title":{"rendered":"Programming Raspberry Pi Remotely using VS Code (Remote-SSH)"},"content":{"rendered":"\n<p>In this tutorial, we&#8217;ll show you a practical way to create and execute files remotely on your Raspberry Pi using VS Code on your computer. All you have to do is to install the Remote-SSH extension on VS Code. This extension allows you to establish an SSH connection with your Pi, create files, write code and execute it directly on your Raspberry Pi board from your computer using VS Code interface. This is the perfect solution if your Raspberry Pi is running headless.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/Raspberry-Pi-Remote-SSH-VS-Code.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi: Create, Code, and Execute Python Files Remotely using VS Code Remote SSH\" class=\"wp-image-125687\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/Raspberry-Pi-Remote-SSH-VS-Code.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/Raspberry-Pi-Remote-SSH-VS-Code.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/Raspberry-Pi-Remote-SSH-VS-Code.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/Raspberry-Pi-Remote-SSH-VS-Code.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>If you&#8217;re reading this post, we assume that you are familiar with or are getting started with the Raspberry Pi. You can read our getting started guide below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-raspberry-pi\/\">Getting Started with Raspberry Pi<\/a><\/li>\n<\/ul>\n\n\n\n<p>We assume you have an operating system installed on your Pi (Raspberry Pi OS or similar), you have <strong>enabled SSH on the Pi<\/strong>, and you know your <strong>Pi hostname<\/strong>, <strong>username, <\/strong>and <strong>password<\/strong> \u2014 all of this is set up during the installation process.<\/p>\n\n\n\n<p>We also assume you already have <a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noopener\">Visual Studio Code (VS Code) installed<\/a> on your computer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Remote &#8211; SSH Extension on VS Code<\/h2>\n\n\n\n<p>First, you need to install the <strong>Remote &#8211; SSH<\/strong> extension on VS Code. Click on the <strong>Extensions <\/strong>icon on the left sidebar, search for <em>remote<\/em>, and install the <strong>Remote &#8211; SSH<\/strong> extension.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"449\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/1-install-remote-ssh-vs-code.png?resize=750%2C449&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing Remote - SSH Extension on VS Code\" class=\"wp-image-125653\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/1-install-remote-ssh-vs-code.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/1-install-remote-ssh-vs-code.png?resize=300%2C180&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Create a Remote Connection with the Raspberry Pi on VS Code<\/h2>\n\n\n\n<p>After installing, a new <em>Desktop <\/em>icon will show up on your sidebar. Click on that icon. Then, select <strong>Remote <\/strong>on the <em>Remote Explorer<\/em> field. Then, Click on the <strong>+<\/strong> sign to add a new remote machine.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"704\" height=\"327\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/2-remote-explorer-ssh.png?resize=704%2C327&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Create Remote Connection with the Raspberry Pi on VS Code\" class=\"wp-image-125654\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/2-remote-explorer-ssh.png?w=704&amp;quality=100&amp;strip=all&amp;ssl=1 704w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/2-remote-explorer-ssh.png?resize=300%2C139&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 704px) 100vw, 704px\" \/><\/figure><\/div>\n\n\n<p>Then, you&#8217;ll be asked to run the SSH command to establish a communication with your host. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"554\" height=\"100\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/3-ssh-comand-vs-code-raspberrypi.png?resize=554%2C100&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"SSH command raspberry Pi VS Code\" class=\"wp-image-125655\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/3-ssh-comand-vs-code-raspberrypi.png?w=554&amp;quality=100&amp;strip=all&amp;ssl=1 554w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/3-ssh-comand-vs-code-raspberrypi.png?resize=300%2C54&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 554px) 100vw, 554px\" \/><\/figure><\/div>\n\n\n<p>At this point, you need to know your Raspberry pi localhost name or IP address and username. For example, in my case:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>localhost: <strong>raspberrypi2<\/strong><\/li>\n\n\n\n<li>IP address: <strong>192.168.1.106<\/strong><\/li>\n\n\n\n<li>username: <strong>pi<\/strong><\/li>\n<\/ul>\n\n\n\n<p>So, I need to write the following command on that field:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh pi@raspberrypi2<\/code><\/pre>\n\n\n\n<p>Or, if I wanted to use the IP address instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh pi@192.168.1.106<\/code><\/pre>\n\n\n\n<p>Then, press <strong>Enter<\/strong>. You&#8217;ll be asked to select an SSH configuration file where VS code will save the SSH settings for that host. You can choose the one under the <em>Users<\/em> folder.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"140\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/4-select-ssh-file.png?resize=607%2C140&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"SSH configuration file VS Code Raspberry Pi\" class=\"wp-image-125656\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/4-select-ssh-file.png?w=607&amp;quality=100&amp;strip=all&amp;ssl=1 607w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/4-select-ssh-file.png?resize=300%2C69&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/><\/figure><\/div>\n\n\n<p>You&#8217;ll get a message saying the host was added.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"99\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/5-remote-host-added-vscode.png?resize=470%2C99&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"New host added to VS Code Remote\" class=\"wp-image-125657\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/5-remote-host-added-vscode.png?w=470&amp;quality=100&amp;strip=all&amp;ssl=1 470w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/5-remote-host-added-vscode.png?resize=300%2C63&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/figure><\/div>\n\n\n<p>On the top left corner, click on the <strong>Refresh<\/strong><em> <\/em>icon next to <strong>Remote<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"717\" height=\"222\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/6-refresh-remote-connections.png?resize=717%2C222&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Refresh remote connections Vs Code\" class=\"wp-image-125658\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/6-refresh-remote-connections.png?w=717&amp;quality=100&amp;strip=all&amp;ssl=1 717w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/6-refresh-remote-connections.png?resize=300%2C93&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 717px) 100vw, 717px\" \/><\/figure><\/div>\n\n\n<p>The Raspberry Pi remote host will show up under the <strong>SSH <\/strong>menu. Then, click on the icon to connect in a new window as shown below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"228\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/7-connect-to-remote-host-new-window.png?resize=750%2C228&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"New Remote connection on new window VS Code\" class=\"wp-image-125660\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/7-connect-to-remote-host-new-window.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/7-connect-to-remote-host-new-window.png?resize=300%2C91&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>This will open a new window in VS Code dedicated to that remote machine (the Raspberry Pi). You&#8217;ll be asked to enter the Raspberry Pi password.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"741\" height=\"487\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/8-enter-password-remote-connection.png?resize=741%2C487&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"insert password for remote connection\" class=\"wp-image-125661\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/8-enter-password-remote-connection.png?w=741&amp;quality=100&amp;strip=all&amp;ssl=1 741w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/8-enter-password-remote-connection.png?resize=300%2C197&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><\/figure><\/div>\n\n\n<p>Now, you have a remote connection established with your Raspberry Pi. Notice that the Terminal window at the bottom is connected to your Raspberry Pi. Any commands that you run on that Terminal window, will be run on the Raspberry Pi.<\/p>\n\n\n\n<p>You can open Raspberry Pi folders on VS Code to start creating and writing files. Click on the <strong>Open Folder<\/strong> button to open a folder on your Raspberry Pi where you want to start creating or editing your files.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"470\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/9-remote-connection-established-open-folder.png?resize=750%2C470&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Open new folder on remote machine SSH VS Code\" class=\"wp-image-125662\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/9-remote-connection-established-open-folder.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/9-remote-connection-established-open-folder.png?resize=300%2C188&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Choose a folder on your Raspberry Pi where you want to start creating your files.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"608\" height=\"309\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/10-open-folder-rpi-remote.png?resize=608%2C309&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Select Remote folder Raspberry Pi on VS Code SSH\" class=\"wp-image-125665\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/10-open-folder-rpi-remote.png?w=608&amp;quality=100&amp;strip=all&amp;ssl=1 608w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/10-open-folder-rpi-remote.png?resize=300%2C152&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 608px) 100vw, 608px\" \/><\/figure><\/div>\n\n\n<p>I chose the <em>Documents<\/em> folder, but you can choose any other location on the Raspberry Pi. The <em>Desktop <\/em>folder might also be a convenient location. After selecting the folder, click <strong>OK<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"609\" height=\"102\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/10-remote-RPi-Open-folder-VS-Code.png?resize=609%2C102&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Select folder for Remote connection SSH Raspberry Pi\" class=\"wp-image-125664\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/10-remote-RPi-Open-folder-VS-Code.png?w=609&amp;quality=100&amp;strip=all&amp;ssl=1 609w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/10-remote-RPi-Open-folder-VS-Code.png?resize=300%2C50&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 609px) 100vw, 609px\" \/><\/figure><\/div>\n\n\n<p>Insert your Raspberry Pi password again.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"632\" height=\"120\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/12-enter-password-after-opening-folder.png?resize=632%2C120&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Enter SSH host password on VS Code\" class=\"wp-image-125667\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/12-enter-password-after-opening-folder.png?w=632&amp;quality=100&amp;strip=all&amp;ssl=1 632w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/12-enter-password-after-opening-folder.png?resize=300%2C57&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 632px) 100vw, 632px\" \/><\/figure><\/div>\n\n\n<p>You&#8217;ll be asked if you trust the authors of the folder. Tick the option <em>Trust the authors of all files in the parent folder &#8216;pi&#8217;<\/em>, and click <strong>Yes, I trust the authors<\/strong> to proceed.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"535\" height=\"338\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/trust-authors-after-opening-folder.png?resize=535%2C338&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Trust authors of the Pi folder Vs Code remote connection with Raspberry Pi\" class=\"wp-image-125682\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/trust-authors-after-opening-folder.png?w=535&amp;quality=100&amp;strip=all&amp;ssl=1 535w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/trust-authors-after-opening-folder.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/figure><\/div>\n\n\n<p>It will open the selected folder on the left sidebar. Now, you can use the VS Code menus to create new files and\/or folders under that folder. To open the Terminal window again, go to <strong>Terminal <\/strong>&gt; <strong>New Terminal<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"457\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/13-open-terminal-on-new-folder-VS-Code-Raspberry-Pi.png?resize=750%2C457&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code Workspace on Remote Raspberry Pi\" class=\"wp-image-125676\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/13-open-terminal-on-new-folder-VS-Code-Raspberry-Pi.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/13-open-terminal-on-new-folder-VS-Code-Raspberry-Pi.png?resize=300%2C183&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Create a New Python File in the Raspberry Pi Remotely using VS Code<\/h2>\n\n\n\n<p>Once you&#8217;ve selected a working folder, you can create and write a new file in that folder. Hover your mouse over the &#8220;<strong>Documents<\/strong>&#8221; tab and click on the <strong>New File&#8230;<\/strong> button to create a new file. For demonstration purposes, you can create a file called <em>test.py<\/em>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"751\" height=\"320\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/13-create-new-file-test-py.png?resize=751%2C320&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Create a New Python File in the Raspberry Pi Remotely using VS Code\" class=\"wp-image-125677\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/13-create-new-file-test-py.png?w=751&amp;quality=100&amp;strip=all&amp;ssl=1 751w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/13-create-new-file-test-py.png?resize=300%2C128&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 751px) 100vw, 751px\" \/><\/figure><\/div>\n\n\n<p>It will create and open a new Python file called <em>test.py<\/em> on the <em>Documents <\/em>folder of the Raspberry Pi filesystem. You can write to that folder using VS Code environment. You can also delete or move that folder from VS Code.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"412\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/14-new-file-test-py.png?resize=750%2C412&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"New file create on remote connection Raspberry Pi SSH\" class=\"wp-image-125678\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/14-new-file-test-py.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/14-new-file-test-py.png?resize=300%2C165&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>At this point, you can write your Python code on that file. For demonstration purposes, copy the following line to that file. This will simply print a message on the Terminal window when executed.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>print(\"Hello from Raspberry Pi\")<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"356\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/15-test-file-raspberry-pi-VS-Code-Remote.png?resize=750%2C356&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Python File on VS Code Raspberry Pi Remote connection\" class=\"wp-image-125679\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/15-test-file-raspberry-pi-VS-Code-Remote.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/15-test-file-raspberry-pi-VS-Code-Remote.png?resize=300%2C142&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Save your file. To save your file you can simply press <strong>Ctrl+S<\/strong> or <strong>Cmd+S<\/strong>.<\/p>\n\n\n\n<p>Now, you have a file called <em>test.py<\/em> on your Raspberry Pi <em>Documents <\/em>folder with that line of code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Running a Python File on the Raspberry Pi Remotely using VS Code (SSH)<\/h2>\n\n\n\n<p>To run that file simply call the command <span class=\"rnthl rntliteral\">python<\/span> followed by the name of the file on the terminal window. In this case:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python test.py<\/code><\/pre>\n\n\n\n<p>Press <strong>Enter <\/strong>after typing the command.<\/p>\n\n\n\n<p>You should get &#8220;<span class=\"rnthl rntliteral\">Hello from Raspberry Pi<\/span>&#8221; on the Terminal window, which is what that files does (prints a message). <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/16-test-py-remote-ssh-demonstration.png?resize=750%2C398&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Run file on Raspberry Pi from VS Code Remote SSH connection\" class=\"wp-image-125681\" width=\"750\" height=\"398\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/16-test-py-remote-ssh-demonstration.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/16-test-py-remote-ssh-demonstration.png?resize=300%2C159&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Closing the Remote Connection with Raspberry Pi on VS Code<\/h2>\n\n\n\n<p>To close the remote session, go to <strong>File <\/strong>&gt; <strong>Close Remote Connection<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"363\" height=\"562\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/17-VS-Code-Raspberry-Pi-Close-Remote-Connection.png?resize=363%2C562&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Close Remote Connection on VS Code\" class=\"wp-image-125683\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/17-VS-Code-Raspberry-Pi-Close-Remote-Connection.png?w=363&amp;quality=100&amp;strip=all&amp;ssl=1 363w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/17-VS-Code-Raspberry-Pi-Close-Remote-Connection.png?resize=194%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 194w\" sizes=\"(max-width: 363px) 100vw, 363px\" \/><\/figure><\/div>\n\n\n<p>Congratulations! Now, you know how to code on Raspberry Pi remotely using VS Code on your computer using the <strong>Remote &#8211; SSH<\/strong> extension.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned a very convenient, practical, and easy way to program on your Raspberry Pi remotely via SSH using VS Code on your computer. Using the Remote &#8211; SSH extension you can create new files and folders on the Pi, and write and execute code using the command line.<\/p>\n\n\n\n<p>This is our favorite method to program the Raspberry Pi, because you don&#8217;t have to manually transfer the files from your computer to the Pi. Using this method, you&#8217;re already writing the code on the Pi. Additionally, the Terminal window allows you to execute commands remotely via SSH on the Pi, which is very practical to run your code.<\/p>\n\n\n\n<p>We hope you found this tutorial useful. If you also like to program boards like the ESP32 and ESP8266, you can also use VS Code for that. Learn how with the following tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/vs-code-platformio-ide-esp32-esp8266-arduino\/\">Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266 (Windows, Mac OS X, Linux Ubuntu)<\/a><\/li>\n<\/ul>\n\n\n\n<p>You can check all our Raspberry Pi projects on the following link:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi\/\" title=\"\">Free Raspberry Pi Projects and Tutorials<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we&#8217;ll show you a practical way to create and execute files remotely on your Raspberry Pi using VS Code on your computer. All you have to do &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Programming Raspberry Pi Remotely using VS Code (Remote-SSH)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-remote-ssh-vs-code\/#more-125652\" aria-label=\"Read more about Programming Raspberry Pi Remotely using VS Code (Remote-SSH)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":125687,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301,264,190,268],"tags":[],"class_list":["post-125652","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-raspberrypi","category-project","category-raspberry-pi","category-raspberry-pi-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/01\/Raspberry-Pi-Remote-SSH-VS-Code.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/125652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=125652"}],"version-history":[{"count":9,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/125652\/revisions"}],"predecessor-version":[{"id":133376,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/125652\/revisions\/133376"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/125687"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=125652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=125652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=125652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}