{"id":237,"date":"2008-11-20T23:58:47","date_gmt":"2008-11-20T21:58:47","guid":{"rendered":"http:\/\/www.netexpertise.eu\/en\/?p=237"},"modified":"2021-08-21T20:47:29","modified_gmt":"2021-08-21T18:47:29","slug":"environment-variables-and-ssh","status":"publish","type":"post","link":"http:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html","title":{"rendered":"Environment Variables and SSH, How to"},"content":{"rendered":"\n<p>Very few environment variables are defined when connecting to a remote host with an authorized <a href=\"\/en\/category\/security\/ssh\">SSH<\/a> key. The <em>env<\/em> command that will list all environment variables available on the remote server shows this is the case (localhost is the target here).<br>\u00a0<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"\/images\/SSH_environment_variables.png\" alt=\"SSH Environment Variables\"\/><\/figure>\n\n\n\n<p><br>Sometimes, you&#8217;d like to pass extra environment variables onto the host along the SSH command. For instance, to run a program calling libs from an unusual location, the LD_LIBRARY_PATH variable has to be set.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><br>If You Have root Access on the Remote Host<\/h2>\n\n\n\n<p>This can be achieved in 2 simple steps:<br><br>&#8211; Add &#8216;<em>PermitUserEnvironment yes<\/em>&#8216; to the sshd_config file on the remote server and restart the SSH daemon.<br>PermitUserEnvironment default value is &#8216;No&#8217; most of the time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ ssh localhost 'sudo sshd -T' | grep -i environment\npermituserenvironment no<\/code><\/pre>\n\n\n\n<p><br>&#8211; Set environment variables in .ssh\/environment in your home directory on the target host in the variable=value format.<br>eg LD_LIBRARY_PATH=\/lib:\/usr\/lib:\/usr\/local\/lib<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Environment Variable as Part of the SSH Command<\/h2>\n\n\n\n<p>If changing the sshd configuration on the remote host is not an option, you can always pass the environment variable along the SSH command. It is less elegant, especially in the previous use case since the path depends on the path libraries have been installed in, on that specific host. The escaping might be tricky, but this solution does the job as well.<br><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ ssh localhost LD_LIBRARY_PATH=\/lib:\/usr\/lib:\/usr\/local\/lib env\nLD_LIBRARY_PATH=\/lib:\/usr\/lib:\/usr\/local\/lib\nSHELL=\/bin\/bash\nSSH_CLIENT=127.0.0.1 53816 22\nUSER=dave\nMAIL=\/var\/mail\/dave\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/usr\/games\nPWD=\/home\/dave\nLANG=en_US.UTF-8\nSHLVL=1\nHOME=\/home\/dave\nLOGNAME=dave\nSSH_CONNECTION=127.0.0.1 53816 127.0.0.1 22\n_=\/usr\/bin\/env<\/code><\/pre>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Very few environment variables are defined when connecting to a remote host with an authorized SSH key. The env command that will list all environment variables available on the remote server shows this is the case (localhost is the target here).\u00a0 Sometimes, you&#8217;d like to pass extra environment variables onto the host along the SSH [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[150],"tags":[395],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netexpertise - Environment Variables and SSH, How to<\/title>\n<meta name=\"description\" content=\"How to pass environment variables through an SSH connection to a remote server? Different ways explained\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netexpertise - Environment Variables and SSH, How to\" \/>\n<meta property=\"og:description\" content=\"How to pass environment variables through an SSH connection to a remote server? Different ways explained\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html\" \/>\n<meta property=\"og:site_name\" content=\"Netexpertise\" \/>\n<meta property=\"article:published_time\" content=\"2008-11-20T21:58:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-21T18:47:29+00:00\" \/>\n<meta name=\"author\" content=\"dave\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@netexpertise\" \/>\n<meta name=\"twitter:site\" content=\"@netexpertise\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html\",\"url\":\"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html\",\"name\":\"Netexpertise - Environment Variables and SSH, How to\",\"isPartOf\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#website\"},\"datePublished\":\"2008-11-20T21:58:47+00:00\",\"dateModified\":\"2021-08-21T18:47:29+00:00\",\"author\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\"},\"description\":\"How to pass environment variables through an SSH connection to a remote server? Different ways explained\",\"breadcrumb\":{\"@id\":\"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.netexpertise.eu\/en\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Environment Variables and SSH, How to\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#website\",\"url\":\"http:\/\/www.netexpertise.eu\/en\/\",\"name\":\"Netexpertise\",\"description\":\"Systems \/ Networks \/ DevOps\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.netexpertise.eu\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\",\"name\":\"dave\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"caption\":\"dave\"},\"sameAs\":[\"http:\/\/www.netexpertise.eu\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Netexpertise - Environment Variables and SSH, How to","description":"How to pass environment variables through an SSH connection to a remote server? Different ways explained","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html","og_locale":"en_US","og_type":"article","og_title":"Netexpertise - Environment Variables and SSH, How to","og_description":"How to pass environment variables through an SSH connection to a remote server? Different ways explained","og_url":"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html","og_site_name":"Netexpertise","article_published_time":"2008-11-20T21:58:47+00:00","article_modified_time":"2021-08-21T18:47:29+00:00","author":"dave","twitter_card":"summary_large_image","twitter_creator":"@netexpertise","twitter_site":"@netexpertise","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html","url":"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html","name":"Netexpertise - Environment Variables and SSH, How to","isPartOf":{"@id":"http:\/\/www.netexpertise.eu\/en\/#website"},"datePublished":"2008-11-20T21:58:47+00:00","dateModified":"2021-08-21T18:47:29+00:00","author":{"@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa"},"description":"How to pass environment variables through an SSH connection to a remote server? Different ways explained","breadcrumb":{"@id":"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.netexpertise.eu\/en\/security\/ssh\/environment-variables-and-ssh.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.netexpertise.eu\/en"},{"@type":"ListItem","position":2,"name":"Environment Variables and SSH, How to"}]},{"@type":"WebSite","@id":"http:\/\/www.netexpertise.eu\/en\/#website","url":"http:\/\/www.netexpertise.eu\/en\/","name":"Netexpertise","description":"Systems \/ Networks \/ DevOps","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.netexpertise.eu\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa","name":"dave","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","caption":"dave"},"sameAs":["http:\/\/www.netexpertise.eu"]}]}},"_links":{"self":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/237"}],"collection":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":0,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}