<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ssh &#8211; Sandy Scott&#039;s Web Spot</title>
	<atom:link href="https://www.sandyscott.net/tag/ssh/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sandyscott.net</link>
	<description>My little corner of the web</description>
	<lastBuildDate>Fri, 05 Jun 2020 11:13:53 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>Server Setup 2: Initial tweaks</title>
		<link>https://www.sandyscott.net/2020/05/server-setup-2-initial-tweaks/</link>
					<comments>https://www.sandyscott.net/2020/05/server-setup-2-initial-tweaks/#respond</comments>
		
		<dc:creator><![CDATA[Sandy]]></dc:creator>
		<pubDate>Mon, 18 May 2020 13:44:51 +0000</pubDate>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ssh]]></category>
		<guid isPermaLink="false">https://www.sandyscott.net/?p=419</guid>

					<description><![CDATA[In this post I&#8217;ll show you a few of the post-installation tweaks that will give us a solid base for the rest of the configuration work. If you don&#8217;t have a cabled connection you&#8217;ll need to get wifi working &#8211; I&#8217;m not going to cover this, as there&#8217;s a huge...<p> <a class="continue-reading-link" href="https://www.sandyscott.net/2020/05/server-setup-2-initial-tweaks/"><span>Continue reading</span><i class="crycon-right-dir"></i></a> </p>]]></description>
										<content:encoded><![CDATA[
<p><em>If this is your first time looking at a post from this series, have a look at this summary: <a href="https://www.sandyscott.net/2020/06/04/server-setup-0-contents/" data-type="666">Server Setup 0: Contents</a></em></p>



<p>In this post I&#8217;ll show you a few of the post-installation tweaks that will give us a solid base for the rest of the configuration work.</p>



<p>If you don&#8217;t have a cabled connection you&#8217;ll need to get wifi working &#8211; I&#8217;m not going to cover this, as there&#8217;s a huge variety of possibilities to work out before you get it working, but there are lots of helpful people out there on the internet if you get stuck.</p>



<h2 class="wp-block-heading">SSH</h2>



<p>This should be all set up, but we&#8217;ll check. First, I&#8217;m assuming your client computer is connected to the same network as the server, which it usually would be.</p>



<p>On you client computer, you&#8217;ll need an SSH client, fortunately all modern OS&#8217;s have one built in. On Windows open <strong>Command Prompt</strong>. On Mac OS, open <strong>Terminal</strong>. On linux, the name of the application can vary, but it&#8217;ll have something like term or terminal in the name.</p>



<p>Type this command, swapping <strong>username</strong> for the user you created when installing the system, and <strong>hostname</strong> for the hostname you created.</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">ssh username@hostname</pre></div>



<p>The first time you do this, you&#8217;ll probably get a warning something like &#8220;The Authenticity of the host could not be established&#8230;.Are you sure you want to continue?&#8221; This is normal, and should only happen once. Type <strong>yes</strong> and press enter to continue.</p>



<p>You&#8217;ll then be prompted for the password &#8211; you created this during the installation.</p>



<p>If it all goes according to plan you&#8217;ll see something like this (obviuosly without the blocked out things):</p>



<figure class="wp-block-image size-full is-resized"><a href="https://www.sandyscott.net/wp-content/uploads/2020/05/image-10.png"><img fetchpriority="high" decoding="async" src="https://www.sandyscott.net/wp-content/uploads/2020/05/image-10.png" alt="" class="wp-image-423" width="372" height="256" srcset="https://www.sandyscott.net/wp-content/uploads/2020/05/image-10.png 743w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-10-300x207.png 300w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-10-150x103.png 150w" sizes="(max-width: 372px) 100vw, 372px" /></a></figure>



<p>The <strong>username@hostname:~$</strong> prompt is a sure sign you&#8217;re logged in properly.</p>



<h2 class="wp-block-heading">If it doesn&#8217;t work&#8230;</h2>



<p>The most likely thing is that your router isn&#8217;t smart enough to pick up the hostname from the server.</p>



<p>Find out the IP address of the server by logging in locally (ie. with a screen and keyboard connected directly to the server) then type ip address and press enter.</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sandy@waldorf:~$ ip address
1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp2s0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:c0:08:8f:ea:e8 brd ff:ff:ff:ff:ff:ff
    inet xxx.xxx.xxx.xxx/24 brd xxx.xxx.xxx.xxx scope global dynamic noprefixroute enp2s0
       valid_lft 857109sec preferred_lft 857109sec
    inet6 fe80::363d:fd19:4c73:a0b3/64 scope link noprefixroute
       valid_lft forever preferred_lft forever</pre></div>



<p>where you see the xxx.xxx.xxx.xxx that&#8217;s the IP address your server has.</p>



<p>Go back to the client and try this command, swapping in the IP address.</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">ssh username@xxx.xxx.xxx.xxx</pre></div>



<h2 class="wp-block-heading">Prevent IP from changing</h2>



<p>Your server got its IP address from the router, but it could change if the server reboots. We don&#8217;t want that. There are 2 ways of doing this:</p>



<h3 class="wp-block-heading">Address reservation</h3>



<p>This is feature of your router &#8211; you&#8217;ll need to refer to the manual for that router to get sepcific instructions, but the basic steps are:</p>



<ol class="wp-block-list"><li>Log into your router</li><li>Find the list of devices on your network</li><li>Find the server in that list.</li><li>Look for an option that says something like &#8220;reserve this IP address&#8221;. On my router it it&#8217;s a tickbox that says <strong>Always assign this network device the same IPv4 address</strong> and looks like this:</li></ol>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://www.sandyscott.net/wp-content/uploads/2020/05/image-11.png" alt="" class="wp-image-424" width="320" height="54" srcset="https://www.sandyscott.net/wp-content/uploads/2020/05/image-11.png 639w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-11-300x50.png 300w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-11-150x25.png 150w" sizes="(max-width: 320px) 100vw, 320px" /></figure>



<h3 class="wp-block-heading">Fixed IP</h3>



<p>This might be a bit more work, but almost all routers should support doing this. The main thing to avoid is you giving the server an address that the router might hand out to something else, so:</p>



<ol class="wp-block-list"><li>Log into your router</li><li>Find the DHCP server settings &#8211; this will basically be two boxes with a minimum and maximum IP address.</li></ol>



<figure class="wp-block-image size-large"><img decoding="async" width="545" height="376" src="https://www.sandyscott.net/wp-content/uploads/2020/05/image-13.png" alt="" class="wp-image-427" srcset="https://www.sandyscott.net/wp-content/uploads/2020/05/image-13.png 545w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-13-300x207.png 300w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-13-150x103.png 150w" sizes="(max-width: 545px) 100vw, 545px" /></figure>



<ul class="wp-block-list"><li>In this example the top line is the router itself &#8211; we can&#8217;t give our server that address.</li><li>The next line is the subnet mask &#8211; without getting in the details, the fact that the last box is zero means that we can pick any address where the first 3 boxes are the same as the server, and the last box is somewhere between 0 and 255.</li><li>The next two boxes are the DHCP range &#8211; the router could give out any address between xxx.xxx.xxx.20 and xxx.xxx.xxx.200 so we can&#8217;t give our server an IP address in there.</li><li>Based on this you could give the server any of these IPs:<ul><li>xxx.xxx.xxx.0 (I wouldn&#8217;t recommend this)</li><li>xxx.xxx.xxx.2 to xxx.xxx.xxx.19</li><li>xxx.xxx.xxx.201 to xxx.xxx.xxx.255</li></ul></li><li>The first and last can sometimes be used for special things, so I&#8217;d probably pick xxx.xxx.xxx.201 for the server.</li></ul>



<p>You can log out of the router now, we aren&#8217;t going to change anything.</p>



<p>Setting fixed IP on the server is a little involved, so I&#8217;ll defer this page:<br><a href="https://linuxconfig.org/how-to-setup-a-static-ip-address-on-debian-linux">https://linuxconfig.org/how-to-setup-a-static-ip-address-on-debian-linux</a><br>You&#8217;ll need to log in locally as root for most of the tasks.</p>



<h2 class="wp-block-heading">Sudo installation</h2>



<p>Sudo is a useful command that lets an ordinary user run commands as root, allowing them to do system administration, which is what we want!</p>



<p>So, first we become root. type <code>su -</code>, press enter, then type the root password and press enter.</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sandy@waldorf:~$ su -
Password:
root@waldorf:~# </pre></div>



<p>The last character of the prompt has become <code>#</code>, signifying that we are now root. The next 3 commands:</p>



<ul class="wp-block-list"><li>Install sudo</li><li>Add username to the people who can use the sudo program</li><li>Exit out of root mode</li></ul>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">apt install sudo
/sbin/adduser username sudo
exit</pre></div>



<p>We need to log out and log back in for this to take effect, so enter <code>exit </code>again then log back in.</p>



<p>Test it:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;sudo Shell&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sudo echo &quot;Hello World&quot;</pre></div>



<p>You should get a warning about taking care when using sudo, and a prompt to enter your password (not the root password). Do that, then <code>Hello world</code> should appear on a new line</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;sandy@waldorf:~$ sudo echo \&quot;Hello world\&quot;&lt;br&gt;We trust you have received the usual lecture from the local System&lt;br&gt;Administrator. It usually boils down to these three things:&lt;br&gt;&lt;code&gt;#1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility.&lt;/code&gt;&lt;br&gt;[sudo] password for sandy:&lt;br&gt;Hello world&lt;br&gt;sandy@waldorf:~$ /sbin/adduser sandy sudoShell&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sandy@waldorf:~$ sudo echo &quot;Hello world&quot;

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for sandy:
Hello world
sandy@waldorf:~$ </pre></div>



<h2 class="wp-block-heading">Set editor</h2>



<p>There are plenty of editors available out there</p>



<ul class="wp-block-list"><li><strong>Nano</strong> is a simple, basic choice that&#8217;s the default on many linux systems.</li><li><strong>Emacs </strong>is a popular &amp; powerful editor with hundreds of commands available.</li><li><strong>Vim </strong>is powerful &amp; customisable but practically unusable until you&#8217;ve mastered the basics.</li></ul>



<p>You can do your own research about which you&#8217;d prefer to use but once you&#8217;ve made your choice, you can make it the default with this command:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sudo update-alternatives --config editor</pre></div>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sandy@waldorf:~$ sudo update-alternatives --config editor
There are 3 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path               Priority   Status
------------------------------------------------------------
* 0            /usr/bin/vim.gtk    50        auto mode
  1            /bin/nano           40        manual mode
  2            /usr/bin/vim.gtk    50        manual mode
  3            /usr/bin/vim.tiny   15        manual mode

Press &lt;enter&gt; to keep the current choice[*], or type selection number: 2
sandy@waldorf:~$         </pre></div>



<p>Have a look at <a href="https://www.sandyscott.net/2020/05/10/copy-paste-from-linux-to-windows-via-ssh/">this post</a> for another optional step &#8211; getting copy &amp; paste working in the terminal.</p>



<h2 class="wp-block-heading">Remove CD Repository</h2>



<p>During the install, the USB stick was treated like an internet respository for installing software. Now we&#8217;re removed it, we might need to tell Debian not to look for it, which will get rid of it to avoid any warnings</p>



<p>Edit the apt sources file:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sudoedit /etc/apt/sources.list</pre></div>



<p>Look for a line the begins <code>deb cdrom:</code>. Put a # at the beginning to comment it out so that line is ignored. Save and exit the file. Finally lets update the cache:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;sudoShell&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sudo apt update</pre></div>



<p>It should go though without any warnings. You might find some packages to upgrade, in which case do so with:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;sudShell&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sudo apt upgrade</pre></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sandyscott.net/2020/05/server-setup-2-initial-tweaks/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Copy/Paste from Linux to Windows via SSH</title>
		<link>https://www.sandyscott.net/2020/05/copy-paste-from-linux-to-windows-via-ssh/</link>
					<comments>https://www.sandyscott.net/2020/05/copy-paste-from-linux-to-windows-via-ssh/#respond</comments>
		
		<dc:creator><![CDATA[Sandy]]></dc:creator>
		<pubDate>Sun, 10 May 2020 21:43:26 +0000</pubDate>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[VcXsrv]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[WSL]]></category>
		<category><![CDATA[WSLtty]]></category>
		<guid isPermaLink="false">https://www.sandyscott.net/?p=296</guid>

					<description><![CDATA[Ever wanted to copy and paste from a Linux machine you&#8217;re SSH&#8217;d into? Then read on! If you haven&#8217;t done already, take a look at my previous post to use wsltty to view the local WSL installation, which is then used to ssh into a remote box. For the purpose...<p> <a class="continue-reading-link" href="https://www.sandyscott.net/2020/05/copy-paste-from-linux-to-windows-via-ssh/"><span>Continue reading</span><i class="crycon-right-dir"></i></a> </p>]]></description>
										<content:encoded><![CDATA[
<p>Ever wanted to copy and paste from a Linux machine you&#8217;re SSH&#8217;d into? Then read on!</p>



<p>If you haven&#8217;t done already, take a look at <a href="https://www.sandyscott.net/2020/05/03/best-ssh-setup-for-windows/">my previous post to use wsltty to view the local WSL installation, which is then used to ssh into a remote box.</a></p>



<p>For the purpose of this explanation the <strong>client </strong>is the machine you&#8217;re sitting at, and the <strong>server </strong>is the remote machine you&#8217;re connecting to.</p>



<p>First, we need to get SSH X11 Forwarding working. This would normally be used for running graphical applications, but we&#8217;re just using it for the clipboard feature.</p>



<h2 class="wp-block-heading">Server Configuration</h2>



<p>You should have these lines uncommented in <code>/etc/ssh/sshd_config</code></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;properties&quot;,&quot;mime&quot;:&quot;text/x-properties&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Properties files&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;properties&quot;}">X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no</pre></div>



<p>When you&#8217;re done restart the ssh daemon, on my (Debian) system the command is this:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sudo systemctl restart ssh</pre></div>



<p>If you&#8217;re running a firewall on the server you need to enable loopback. I&#8217;m using iptables, so this is how I&#8217;d do it:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sudo iptables -I INPUT -i lo -j ACCEPT
sudo iptables -I OUTPUT -o lo -j ACCEPT
su -
iptables-save &gt; /etc/iptables/rules.v4
exit</pre></div>



<h2 class="wp-block-heading">Client configuration</h2>



<p>From within WSL (but not ssh&#8217;d into a remote system), Install xauth and xterm:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sudo apt install xauth xterm</pre></div>



<p>A big thanks to this video for help with the next section: <a href="https://www.youtube.com/watch?v=_MgrjgQqDcE">youtube.com/watch?v=_MgrjgQqDcE</a></p>



<p>In Windows, download and install VcXsrv <a href="https://sourceforge.net/projects/vcxsrv/">https://sourceforge.net/projects/vcxsrv/</a></p>



<p>Find XLaunch in the start menu and run it. </p>



<p>On the first screen choose <strong>Multiple Windows</strong> and set the <strong>Display number</strong> to 0:</p>



<figure class="wp-block-image size-large is-resized"><a href="https://www.sandyscott.net/wp-content/uploads/2020/05/image.png"><img loading="lazy" decoding="async" src="https://www.sandyscott.net/wp-content/uploads/2020/05/image.png" alt="" class="wp-image-302" width="250" height="196" srcset="https://www.sandyscott.net/wp-content/uploads/2020/05/image.png 499w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-300x236.png 300w" sizes="(max-width: 250px) 100vw, 250px" /></a></figure>



<p>Choose <strong>Start no client</strong> on the next page:</p>



<figure class="wp-block-image is-resized"><a href="https://www.sandyscott.net/wp-content/uploads/2020/05/image-1.png"><img loading="lazy" decoding="async" src="https://www.sandyscott.net/wp-content/uploads/2020/05/image-1.png" alt="" class="wp-image-303" width="250" height="196" srcset="https://www.sandyscott.net/wp-content/uploads/2020/05/image-1.png 499w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-1-300x236.png 300w" sizes="(max-width: 250px) 100vw, 250px" /></a></figure>



<p>Make sure <strong>Clipboard</strong> is turned on</p>



<figure class="wp-block-image size-large is-resized"><a href="https://www.sandyscott.net/wp-content/uploads/2020/05/image-2.png"><img loading="lazy" decoding="async" src="https://www.sandyscott.net/wp-content/uploads/2020/05/image-2.png" alt="" class="wp-image-304" width="250" height="196" srcset="https://www.sandyscott.net/wp-content/uploads/2020/05/image-2.png 499w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-2-300x236.png 300w" sizes="(max-width: 250px) 100vw, 250px" /></a></figure>



<p>Press <strong>Save configuration</strong>. </p>



<figure class="wp-block-image size-large is-resized"><a href="https://www.sandyscott.net/wp-content/uploads/2020/05/image-3.png"><img loading="lazy" decoding="async" src="https://www.sandyscott.net/wp-content/uploads/2020/05/image-3.png" alt="" class="wp-image-305" width="250" height="196" srcset="https://www.sandyscott.net/wp-content/uploads/2020/05/image-3.png 499w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-3-300x236.png 300w" sizes="(max-width: 250px) 100vw, 250px" /></a></figure>



<p>Type <strong>shell:startup</strong> in the address bar and hit enter &#8211; this will take you to a special folder &#8211; files saved here will run when a user logs in. The filename should be pre-populated as <strong>config.xlaunch</strong>. That&#8217;s OK so hit <strong>Save</strong>, and then <strong>Finish</strong> in the previous window.</p>



<figure class="wp-block-image size-large is-resized"><a href="https://www.sandyscott.net/wp-content/uploads/2020/05/image-5.png"><img loading="lazy" decoding="async" src="https://www.sandyscott.net/wp-content/uploads/2020/05/image-5.png" alt="" class="wp-image-331" width="347" height="211" srcset="https://www.sandyscott.net/wp-content/uploads/2020/05/image-5.png 694w, https://www.sandyscott.net/wp-content/uploads/2020/05/image-5-300x182.png 300w" sizes="(max-width: 347px) 100vw, 347px" /></a></figure>



<p>Finally, go back to WSL. This command tells your local WSL (the client) where to find the display. SSH uses that information when you link to the remote computer (server).</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">export DISPLAY=localhost:0</pre></div>



<p>You can also save this line into <code>~/.bashrc</code> on the client to load it every time WSL starts.</p>



<h2 class="wp-block-heading">Connect and Test</h2>



<p>In WSL, connect to the server with a slightly modified command:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">ssh -Y joebloggs@remotelinuxcomputer.example.com</pre></div>



<p>The <strong>-Y</strong> tells ssh you want to link the server to the VcXsrv software, so the server can display things on the client&#8217;s screen.</p>



<p>Let&#8217;s test with xeyes</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">sudo apt install xeyes
xeyes</pre></div>



<p>A pair of eyes should appear on your screen, and follow the mouse around.</p>



<h2 class="wp-block-heading">Put it to use!</h2>



<p>So, what we have now is that anything that goes onto the Linux system clipboard (xclip) should end up on the Windows clipboard too. Lets give it a try. Pipe some data to xclip:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">echo &quot;I'm copied, paste me!&quot; | xclip -i</pre></div>



<p>Now try pasting that into a text editor on windows.</p>



<p>Next, copy some text in windows, then go back to your ssh session and type:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">xclip -o</pre></div>



<p>The text you copied should appear on a new line in the terminal.</p>



<p>The real power of this comes when combined with terminal applications that are aware of the system clipboard. For me, I wanted to copy from <code>vim</code> in an ssh session, and then paste into windows. If you&#8217;re using a version of vim with enough features (I use <code>vim-gtk</code>), all you have to do is add this to your <code>~/.vimrc</code>:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">&quot; Yank goes to system clipboard, to aid with WSL copy/paste
set clipboard=unnamedplus</pre></div>



<p>Now, anything copied by the yank commands ends up in the windows clipboard too.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sandyscott.net/2020/05/copy-paste-from-linux-to-windows-via-ssh/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
