Alicia Quatermain & The Stone of Fate for iPad, iPhone, Android, Mac & PC! Accompany Alicia Quatermain on her latest time-management adventure and help save the world and get the treasure!! Mac: Discontinue Application Filter (for Mac OS Big S) 3.9.0.2161 2020-07-11. New network driver for Windows: improves speeds for OpenVPN, Wireguard, OpenWeb significantly (700+ mbit/sec) support for PPPoE connection on linux; compatibility with upcoming Mac OS 11 for OpenVPN/Wireguard; windows installer ships 64-bit and 32-bit versions of software.
-with thanks to Bob Harris, who generously and patiently helped me through this the first time, on Apple Discussions
I note that some of the details of menus and options vary as we progress through operating systems, but I believe that it's clear enough. Ask if anything is unclear.
This is to have Internet access to your base computer (home, office, etc.), one name for which is the 'server', from another computer at a different location (different room or different continent), the 'client'. (In my case, the server is an Apple desktop computer - an 'ordinary' desktop computer - and the client is a Mac laptop/notebook computer - which makes sense for me but is not otherwise relevant.)
This access is strongly and securely encrypted, so that no one eavesdropping on a router along the way can decipher your data, and apparently it will often 'tunnel' through otherwise difficult outgoing firewalls (from wherever you are with your 'client' computer), although I have seen this fail.
There are probably several approaches to this, but the one described here uses an 'SSH tunnel' ('SSH' meaning 'Secure Shell'), including its optional Public/Private Key feature. No one can reasonably infiltrate your tunnel without both keys, either of which is kept on only one of the two computers, and which are not reverse-decrypt-able in practical terms, and which themselves can be further password-protected for multiple layers of security.
And the wonderful thing about all of this is that it's included in Mac OS X at no extra charge; all you have to do is learn how to do it (which will however require some time)!
Alternatives: there are commercial software programs which will do this for you, but I didn't find them much easier than doing it this way. I have not looked at Apple's own 'Remote Desktop' program, which is a bit pricey. I haven't really looked at how iCloud might function in this context. Connecting to a non-Mac computer or to earlier versions of Mac OS X may be possible with further knowledge, which however I do not have. And so on; this is just one approach of many.
The following will make more sense perhaps after reading the 'How?' section below, but I want to state up here near the top that I have had recent troubles, and that I have solved them.
Upgrading in the Autumn of 2019 to a new Mac Mini, using OS X 10.15 (Catalina): the tunnel crumped. I changed many settings and spent too long peering into help files and user forums, without any joy. The local (client) computer said, 'connection refused' at the Remote Login port, and would not budge. This persisted over many days.
One day it suddenly worked again, and all has been well, and ... I'm not quite sure what I did. (Sorry!) Whether this has anything to do with the Mini's new hardware security chip, I do not know. Whether it relates to new features of 10.15, I also do not know. I am not alone in having access challenges, but was unable to locate any information on my exact scenario. But here are a few observations which may help you.
The main thing seems to have been converting from AFP to SMB for file-sharing. (But I may be wrong about that.) Apple has recently 'deprecated' (what a word the geeks have chosen; dictionary definition: 'express disapproval of'!) file-sharing using the AFP protocol, and has joined much of the rest of the (computer) world, as I understand it, by using SMB, and: SMB uses a different port! So everywhere below where you see port 445 (SMB), it used to be 548 (AFP). (No matter that I had the Sharing settings configured to use both - my tunnel suddenly became happy soon after settling on SMB; it took me a while to wonder if that meant using a different port - it did.)
Now ... the 'connection refused' message referred to the Remote Login port, not the File Sharing port, so ... go figure.
In the Privacy panel of the Security & Privacy settings, I have added Terminal under Accessibility and under Full Disk Access. Here and there around yer InterWeb I have found suggestions for many other settings, none of which have been helpful nor necessary for me.
I adjusted users, in Sharing, under Screen Sharing, File Sharing, and Remote Login, first of all separating out another account so that I'm not logging into an administrator account (safer that way, apparently), but I don't think that's the answer. Nonetheless, both the 'Standard' and 'Admin' users are included. There is no way I found to include the user from the local client computer, and it is working without that. Specifying, where possible, 'All users' did not help, and I have reverted to 'Only these users:'.
It didn't appear to have anything to do with replacing the Airport Extreme Router - no longer available from Apple or from anyone - with a LinkSys router; that worked fine for months until I got the 2019 Mini with OS X 10.15. However, I did rearrange the order of port-forwardings to put 22 - Remote Login - first.
The old section on this page about how to configure an Airport Extreme has therefore been removed. Every router will be different. Read your help files. (If you can't read your help files, then you possibly shouldn't be reading this page.)
On my new Linksys, I needed to assign at least one permanent IP to the remote host, and that is at Connectivity, Local Network, DHCP Reservations. I put my static ports inside the dynamic range - a change from my older (now broken) Airport wireless router. I needed to forward three ports - more below - and that is at Security, Apps and Gaming, Single Port Forwarding.
During the somewhat random debugging of my SSH tunnel failure, I used a port-testing website to see what was open (and/or visible) and closed. I rather doubt that the resulting information contributed, but there it is in case you might find it helpful. The redirected ports, by the way, all seemed to be working as specified, and the native ports - 22, 445 and 5900 - could not even be seen (good!).
I tried disabling the Firewall on the remote host, and it didn't help. I have re-enabled it. All remains well. Under Advanced, I find that my three sharing services are there, as well as one other, and ... I didn't do any of that. The OS did it by itself. Obviously (I think), I have not selected 'Block all incoming connections', and I have not selected 'Enable stealth mode', and the other settings as found are fairly liberal.
OS X 10.15 in Terminal now uses, by default, zsh instead of bash. I have tried it using both, and that didn't seem to be a factor either.
At various points, if making substantial settings changes, then I of course rebooted both computers and the wireless router.
N.B. I have trouble getting the 'scp' command to work consistently. Recently I first connected the two computers, just on the same private network, using Finder, so that ClientAcct shows up on ServerAcct and vice versa, and then the 'scp' command worked. There are several ways to do this connection, and most readers of this page will already know how: 'File Sharing' is already enabled (above). Find 'Network' or 'Shared' in Finder and go from there. You'll need to know the name and passwords for what we're calling here 'ClientAcct' and 'ServerAcct'. Terminal's 'scp' command (from ClientAcct) will also then ask you for the ServerAcct password - not your 'SSH key' password' - in order to perform its function. 'ssh' will ask for the same type of information, in the next step.
And that's it! Your encrypted SSH tunnel is up and functioning, and you can use File Sharing and Screen Sharing immediately.
It won't be as nearly fast over the Internet as on a private network, but it will work.
Sometimes, however, my tunnel collapses and I have to restart it. Rarely, it just doesn't work, and then two hours later, it may suddenly cooperate. If the server locks up, you're out of luck. I have mine to set to power back on automatically after a power failure (cool!).
Screen Sharing is faster if you 'Turn Scaling On' (View menu) and also use 'Adaptive' video resolution. You can copy and paste back and forth between the server and client computer from the Screen Sharing Edit menu, or from buttons in the Screen Sharing Toolbar.
(I remember all of the numbers by keeping them in a password-protected virtual disk on my computer[s], but that's another story.)
This didn't seem to happen as often in the past as it does now, that the tunnel collapses, with the message: 'Write failed: Broken pipe'. Sometimes that's because the server times out after some undetermined period of inactivity. There are several places around the Web which discuss options to tame this behaviour, but the best option for me seemed to be to place a file called 'config' (with very restrictive permissions) inside the .ssh folder on the client. That file on my client computer contains exactly this:
Apparently, indenting the second line matters(?!). Anyway, this sends a tiny confirmation (i.e. low overhead) every 300 seconds to the server, more or less saying, 'I'm still here. Keep the tunnel open!' You'll need to know how to use the move ('mv') or copy ('cp') command if you use TextEdit to make the file, and how to do the addressing. For example, from your client account 'Home' folder, presuming that you've created 'config' there:
The restrictive permissions could be like this:
These five commands i) change to the .ssh folder, ii) remove 'ACL permissions' (if any), iii) limit use of the config file to the owner only, iv) show the permissions of all the files in the folder, and v) change back to the 'Home' folder. The listing for the config file on my computer looks like this:
I like lots of password protection, but haven't quite deduced why, when I occasionally have to re-initialize my SSH files, they vary. Recently, I was asked for no passwords at all. Using this commands on the client, starting from the home folder:
resulting in being asked for the private (client) key password (but I had to reboot the computer first before that happened).
Interesting: having redone the entire procedure from scratch (because replaced internal hard drive), all of the permissions presumably went back to default, and my Client now logs in with no password requests. So, will update the permissions of course (on both computers?).
A few things have come up, as of 2015 February, so here they are:
So, having written it down, no wonder it took a while the first time. There's a lot to it.
Enjoy! Questions, comments and suggestions always welcome, but remember that this isn't my 'area'.
Charles T. Low
So far in this series of posts on ssh
on macOS:
Please consider supporting Scripting OS X by buying one of my books!
We have learned so far that ssh
is a really useful and flexible protocol. It can be used to connect securely to a remote shell, or to transfer files securely.
Rather than providing the shell itself, ssh
provides a secure way to transmit data to and from the remote shell. In a similar way, ssh
can be used to provide access to other remote services as well.
Access to important services are usually blocked behind a firewall or router. Since ssh
, when setup correctly, is quite secure, you can usually get access to a server with ssh
even when other protocols are blocked. (Though some administrators move ssh
access to a different port than the default 22.)
You can use ssh
port forwarding or ‘tunneling’ to gain access to other services through ssh
.
Imagine you want to use Screen Sharing to connect to a remote Mac (remote.example.com
). Screen Sharing on macOS uses the VNC port 5900
to connect to a remote Mac. Since VNC itself is inherently insecure, (mac Screen Sharing adds a few things to make it more secure) this port is blocked by many firewalls.
However, I do have ssh
access to remote.example.com
. So, how do I tell both systems to ‘tunnel’ the screen sharing traffic through ssh
?
(When you test this, remember to enable either ‘Screen Sharing’ or ‘Remote Management’ (i.e Apple Remote Desktop) access in the ‘Sharing’ pane in System Preferences on the remote Mac.)
The tunnel starts on my local machine and ends on remote.example.com
at port 5900 (where the screen sharing service is listening on the remote Mac.)
The starting point also needs a port number, and I can basically choose freely. Port numbers under 1000 and over 49000 are reserved for the system and require root privileges. There are also many numbers that are commonly used by certain services (such as 5900 for VNC/Screen Sharing) and may already be in use. I will choose 5901 for the local port.
To connect the local port 5901 to port 5900 on the remote Mac use the following command:
(You can just try this with a second Mac or virtual machine in your network, even without a firewall.)
The syntax of this command is less than obvious. Let’s break it into pieces:
The -N
option tells ssh
that we do not want to invoke a remote shell or run a remote command.
The -L
option creates a local port forwarding setup. This option takes a parameter with three or four parts, separated by colons :
. The first pair (localhost:5901
) are the tunnel start point. The second pair (localhost:5900
) are the remote end point of the tunnel.
The second localhost
is resolved on the remote host, so this means port 5900
on the remote host.
The last parameter states the remote host, to connect to, remote.example.com
.
This commands tell ssh
to connect to remote.example.com
and establish a tunnel that transfers traffic from port 5901 on my computer to port 5900 on the remote computer.
Since the origin of my tunnel is usually on my local computer, the first localhost
can be omitted, so you only see the origin port.
When you execute the command nothing will happen. You will not even get a new prompt, because the ssh
process is running until you cancel it with ctrl-C. Don’t cancel it yet, however, since it needs to run to provide the tunnel.
So, when you open the Screen Sharing application (from /System/Library/CoreServices/Applications/
) and connect to localhost:5901
all traffic will be forwarded by ssh
to port 5900 on the remote Mac.
You can also use the open
command to connect with Screen Sharing:
You should be able connect with Screen Sharing, even when port 5900 is blocked by a Firewall.
When you are done with the Screen Sharing session, you can end the ssh
tunnel process in Terminal with ctrl-C.
You can also use ssh
port to use the remote host as a gateway or ‘jump host’ to a third computer. Imagine you want to use Screen Sharing to connect to secundus.example.com
behind a firewall and you only have ssh
connection to primus.example.com
available. You can tell primus
to point the endpoint of an ssh
tunnel at secundus
with:
Note: secundus.example.com
or whatever host or IP address you enter there will be resolved on the remote host. So you can use NAT IP addresses or .local
host names here, even if they do not make sense in the network your work Mac is in. (They do have to make sense on the remote host, though, otherwise you will get an error.)
In the following examples the local IP address 192.168.1.200
or the Bonjour hostname Secundus.local
will be resolved on the remote host, even if they don’t work on my local computer:
Either way, you can then point Screen Sharing at localhost:5902
and it will connect through primus
to Screen Sharing on secundus
.
Keep in mind, that while the connection from the start point (on your Mac) to the host primus
is secured by ssh
the connection from primus
to secundus
is not.
In general you can use ssh
port forwarding (or tunnels) for any service. Some services however, may introduce extra pitfalls.
For example, I wanted to use ssh
port forwarding to gain access to my home router’s web interface. I can use ‘Back to My Mac’ to ssh
into one of the iMacs at home, and thought it should be easy to connect to the router with an ssh
tunnel:
This seemed to work, but whenever I tried to point a browser to localhost:8080
it couldn’t connect to the web page. The problem here is not the ssh
tunnel but the the web server on the router. As part of the http
request, the browser sends the name of the domain requested to the web server. This allows web servers to host different pages for different domains. With this request, the browser told the router it wanted the web page for localhost
and the router replied with “I don’t serve pages for that host”… (Your router might behave differently.)
With curl
I could convince the router to serve me the page with:
However, since navigating the web interface of the router with curl
is out of the question I had to find a different solution.
What if I could send all traffic through the iMac at home?
With the command
I can create a tunnel from my computer (on port 9001) to the remote Mac that acts as a SOCKS proxy. Then I can set the Socks proxy to localhost:9001
in the proxy tab in the Network pane in System Preferences. You probably want to create a new network location for this setup. Then all network traffic will be securely routed through the ssh
tunnel to my Mac at home where it can connect to the router.
This can also serve as a temporary VPN solution.
However it is somewhat painful to set up and maintain, so if you start using this more frequently, you probably need to look into a proper VPN service solution (some routers, ironically, provide one…).
ssh
tunnelssh
to tunnel all trafficPrevious Post: Transferring Files with ssh