{"id":423,"date":"2021-09-21T12:57:57","date_gmt":"2021-09-21T12:57:57","guid":{"rendered":"https:\/\/ni.cmu.edu\/computing\/?post_type=ht_kb&#038;p=423"},"modified":"2026-06-15T16:10:59","modified_gmt":"2026-06-15T16:10:59","slug":"ssh-vscode-setup","status":"publish","type":"ht_kb","link":"https:\/\/ni.cmu.edu\/computing\/knowledge-base\/ssh-vscode-setup\/","title":{"rendered":"SSH and VSCode Setup"},"content":{"rendered":"<h3>Recommendations for Remote Development using SSH and VSCode<\/h3>\n<p>The Visual Studio Code Remote &#8211; SSH extension allows you to open a remote folder on any remote machine, virtual machine, or container with a running SSH server and take full advantage of VS Code&#8217;s feature set. Once connected to a server, you can interact with files and folders anywhere on the remote filesystem.<\/p>\n<p>Users Gabriel Sarch and Nicholas Blauch hypothesize that the resources used by a large number of users running Visual Studio code (or other remote development tools) on the head node is contributing to some of the slowdowns users have been seeing. The following is a solution they found to connect these processes to the compute nodes instead of the head node. If their hypothesis is correct, we expect users adopting this method will reduce resources used by VSCode on the head node and improve its performance for all users.<\/p>\n<p>The following is also a must read if you are going to use VScode to launch jobs!!!!<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"eKhROZFxkf\"><p><a href=\"https:\/\/ni.cmu.edu\/computing\/using-ssh-safely-alongside-slurm\/\">Using SSH Safely Alongside Slurm<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"\u201cUsing SSH Safely Alongside Slurm\u201d \u2014 CMU Neuroscience Institute Computing\" src=\"https:\/\/ni.cmu.edu\/computing\/using-ssh-safely-alongside-slurm\/embed\/#?secret=cLkAKjDJ09#?secret=eKhROZFxkf\" data-secret=\"eKhROZFxkf\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h5>How to use VsCode interactive Python capabilities on a compute node<\/h5>\n<h6><em> The following content is from <a href=\"https:\/\/stackoverflow.com\/questions\/60141905\/how-to-run-code-in-a-debugging-session-from-vs-code-on-a-remote-using-an-interac\/66389686#66389686\">this Stack Overflow solution.<\/a><br \/>\n<\/em><\/h6>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\">\n<ol>\n<li>ssh to the remote cluster <code>ssh username@mind.cs.cmu.edu<\/code><\/li>\n<li>Once on the cluster, add your public key to the <em>authorized<\/em> keys.\u00a0 You will typically append the content of <code>~\/.ssh\/id_rsa.pub<\/code> (on your local machine) to <code>~\/.ssh\/authorized_keys<\/code> (on the cluster) <strong>Note<\/strong>: <em>To configure SSH authorized keys you may need to generate an SSH key pair on your local computer (i.e. terminal for unix, powershell for windows). To do this, use <code>ssh-keygen<\/code>, which is included with the standard OpenSSH suite of tools. You will need to find the the .pub file based on the output path of the ssh-keygen tool.<\/em><\/li>\n<li>Allocate some resources inside the cluster (<code>srun --pty bash<\/code>).\u00a0 You can do this in a screen session so that the job stays running even after you log out.<\/li>\n<li>Get the name of the compute node, typically visible in the command line as <code>username@mind-x-x<\/code>).<\/li>\n<li>On your local machine, modify the <code>~\/.ssh\/config<\/code> file. Using Gabriel&#8217;s example, modify your ssh config file, replacing Gabriel&#8217;s userid with yours :<\/li>\n<\/ol>\n<pre><code>Host mind.cs.cmu.edu\r\n   HostName mind.cs.cmu.edu\r\n   User gsarch\r\n\r\nHost mind-*\r\n    HostName %h\r\n    ProxyJump mind.cs.cmu.edu\r\n    User gsarch<\/code><code><\/code><\/pre>\n<blockquote><p>Since the compute nodes are not directly accessible from outside the cluster, we are configuring a proxy jump.<\/p>\n<p>A proxy jump in SSH (Secure Shell) is a way to connect to a remote server through an intermediary server.\u00a0 This is particularly useful when the target server is not directly accessible from your local machine but can be reached through another server that you have access to.<\/p>\n<p><em>(For this explanation I am going to use compute node <strong>mind-1-1<\/strong> but this applies to all compute nodes)<\/em><\/p>\n<p>When you set up a proxy jump, your SSH connection first goes to the jump host (mind.cs.cmu.edu) and then from there, it connects to the target server mind-1-1. This is done seamlessly, so you only need to issue a single\u00a0 command to reach the target machine. (Your local machine connects to mind.cs.cmu.edu and mind.cs.cmu.edu then connects to the target machine (in this case we are using, mind-1-1)<\/p><\/blockquote>\n<p>Once the changes to the ssh config file are applied, you will be able to access the node directly from VSCode by:<\/p>\n<ol>\n<li>CTRL+P &gt; Remote-SSH: Connect to Host\u2026<\/li>\n<li>Type the compute node name mind-x-x (e.g. mind-1-1) at the prompt (do NOT select mind.cs.cmu.edu).<\/li>\n<li>You will get connected to the node, now every interactive python you run (including jupyter and jupytext) will have access to your allocated resources<\/li>\n<\/ol>\n<p>The node can also be directly accessed with &#8220;ssh mind-x-x&#8221;.<\/p>\n<\/div>\n<blockquote><p>Useful tip:<\/p>\n<p>Command to find the GPU ID slurm allocated to your job.<\/p>\n<p><code>$ scontrol show job -d 12345 | grep -i 'Gres=gpu'<br \/>\nNodes=mind-1-30 CPU_IDs=26-29 Mem=14336 GRES=gpu(IDX:1)<\/code><\/p>\n<p>Where IDX:1 == \/dev\/nvidia1<\/p><\/blockquote>\n<\/div>\n<h2>Step-by-Step Guide to Using SSH, SLURM and VSCode on mind.cs.cmu.edu<\/h2>\n<ol>\n<li><strong>Download and Install PuTTY (Windows Users Only)<\/strong>\n<ul>\n<li>If you\u2019re using Windows, you\u2019ll need an SSH client like PuTTY. You can download it from here.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Log onto the Head Node<\/strong>\n<ul>\n<li><strong>For Windows Users<\/strong>:\n<ul>\n<li>Open PuTTY.<\/li>\n<li>Enter <code>mind.cs.cmu.edu<\/code> as the Host Name and click \u201cOpen\u201d.<\/li>\n<li>Log in with your username and password.<\/li>\n<\/ul>\n<\/li>\n<li><strong>For macOS Users<\/strong>:\n<ul>\n<li>Open the Terminal application.<\/li>\n<li>Connect to the head node by entering the following command:\n<pre><code class=\"language-sh\">ssh your_username@mind.cs.cmu.edu\r\n<\/code><\/pre>\n<\/li>\n<li>Replace <code>your_username<\/code> with your actual username.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>Request a Compute Node Using SLURM<\/strong>\n<ul>\n<li>Once logged in, request a compute node by running the following command:\n<pre><code class=\"language-sh\">srun -p cpu --mem=30GB --time=4:00:00 --pty bash\r\n<\/code><\/pre>\n<\/li>\n<li>This command requests a node from the <code>cpu<\/code> partition with 30GB of memory for 4 hours.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Identify Your Assigned Compute Node<\/strong>\n<ul>\n<li>After running the command, you\u2019ll see a prompt similar to this:\n<pre><code class=\"language-sh\">[dpane@mind ~]$ srun -p cpu --mem=30GB --time=4:00:00 --pty bash\r\n[dpane@mind-0-37-1 ~]$\r\n<\/code><\/pre>\n<\/li>\n<li>This indicates that SLURM has assigned you the compute node <code>mind-0-37-1<\/code>.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Connect to the Compute Node Using VSCode<\/strong>\n<ul>\n<li>Open VSCode and use the Remote &#8211; SSH extension to connect to the assigned compute node.<\/li>\n<li>In VSCode, go to the Command Palette (Ctrl+Shift+P) and select <code>Remote-SSH: Connect to Host...<\/code>.<\/li>\n<li>Enter the compute node address, e.g., <code>mind-0-37-1<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>Important Note<\/h3>\n<ul>\n<li><strong>Dynamic Node Assignment<\/strong>: Each time you request a compute node, you may be assigned a different one. Always check the node assigned to you before connecting with VSCode.<\/li>\n<\/ul>\n<h2>Problem solving<\/h2>\n<p><i>(Vladislav Ayzenberg provided some of the\u00a0 information for this section)<\/i><\/p>\n<h4>Can I run VS Code Server on older Linux distributions?<\/h4>\n<p>https:\/\/code.visualstudio.com\/docs\/remote\/faq#_can-i-run-vs-code-server-on-older-linux-distributions<\/p>\n<p>Several users have recently reported issues with the newer versions of VSCode, which appear to be incompatible with the current OS version on Mind. The upcoming OS upgrade during the scheduled downtime is expected to resolve this. In the meantime, please use VSCode version 1.85.<\/p>\n<p>Try using 1.85 &#8211; https:\/\/code.visualstudio.com\/updates\/v1_85<\/p>\n<h4>Solving Initial Connection issues<\/h4>\n<p>When initially configuring VSCode, pay close attention to the permissions of the files and directories (i.e. private and public certificates and .ssh directory).<\/p>\n<p><i>The following solution partially taken from this stack exchange solution [<a href=\"https:\/\/superuser.com\/questions\/215504\/permissions-on-private-key-in-ssh-folder\/215506#215506\">https:\/\/superuser.com\/questions\/215504\/permissions-on-private-key-in-ssh-folder\/215506#215506<\/a> ] <\/i><\/p>\n<p><u>MacOS\/UNIX File\/Directory File Permissions<\/u><br \/>\n<em>(Windows computer private\/public key management and permissions differ from these instructions. However, they are equally as important to configure correctly.)<\/em><\/p>\n<p>This help page has general information about <a href=\"https:\/\/ni.cmu.edu\/computing\/knowledge-base\/file-and-directory-permissions\/\">File and Directory Permissions<\/a>.<\/p>\n<p>On your local machine, open a terminal window and confirm you are in your home directory.<\/p>\n<pre>imac:~ jim$ pwd\r\n\/Users\/jim<\/pre>\n<p>If you are not in your home directory, you can use the following `cd` command to change to it.<\/p>\n<pre>imac:~ jim$ cd ~<\/pre>\n<p>Confirm that the .ssh directory has the correct permission. Running the following command should give you permission results similar to this..<\/p>\n<pre>imac:~ jim$ ls -la | grep .ssh\r\ndrwx------   6 jim  staff    192 Oct 11  2019 .ssh&lt;\/pre\r\n\r\nIf the permissions aren't set correctly (drwx------ ) on your ~\/.ssh directory, use the following command to set it:<\/pre>\n<pre>imac:~ jim$  chmod 700 ~\/.ssh\/<\/pre>\n<p>You can check the file permission in the .ssh directory and should confirm they have the following permissions.<\/p>\n<pre>imac:~ jim$ ls -l ~\/.ssh\/\r\n-rw-------  1 jim  staff  0 Jun 29 11:43 authorized_keys\r\n-rw-------  1 jim  staff  0 Jun 29 11:43 id_rsa.pub\r\n-rw-r--r--  1 jim  staff  0 Jun 29 11:42 id_rsa\r\n<\/pre>\n<p>If they don&#8217;t have the correct permission, use the following commands to change them to the appropriate settings.<\/p>\n<pre>\tchmod 644 ~\/.ssh\/id_rsa.pub\r\n\tchmod 600 ~\/.ssh\/id_rsa\r\n\tchmod 600 ~\/.ssh\/authorized_keys\r\n<\/pre>\n<h4>VSCode connection suddenly stops working<\/h4>\n<p>If you suddenly experience issues connecting to the cluster from VSCode after it had been working (regardless of what node you use). Try resolving the issue by simply deleting the .vscode-server\/ directory in your home directory and then try reconnecting. This forces VScode to re-install the dependencies it needs the next time it reconnects.<br \/>\n<em>(Note: The time to delete the .vscode-server\/ directory may take a while. You may need to manually reinstall some extensions next time you connect.)<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using VsCode interactive Python capabilities on a compute node.<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[11],"ht-kb-tag":[],"class_list":["post-423","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-software"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb\/423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/comments?post=423"}],"version-history":[{"count":44,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb\/423\/revisions"}],"predecessor-version":[{"id":724,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb\/423\/revisions\/724"}],"wp:attachment":[{"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/media?parent=423"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb-category?post=423"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb-tag?post=423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}