How to Remote SSH into a Mac in 2022
I have two Mac Book Pro, one with an Intel and one with an M1 processor. From time to time I need to run some code on the Intel-Mac, e.g. Docker images that are only available for Intel-chipsets.
Instead of switching between the two Macs, I rather open a terminal window on one and use the other one remotely.
Let’s say my main workstation is A and I want to SSH into B.
Here are the steps that need to be performed in order to setup the two machines for remote SSH operation.
On B, the “Remote Login”-option needs to be enabled first. This can be found under “System Preferences → Sharing”
On Mac A an SSH key needs to be generated.
In directory ~/.ssh
the key generation is triggered with.
ssh-keygen -f macb
I usually give the keys a certain name so I know which is which. For simple development purposes I keep all the options default and the passphrase empty.
Now the public key needs to be copied to machine B with the below command, whereas youruser
and host
needs to be replaced accordingly.
ssh-copy-id -i macb.pub <youruser>@<host>
Now it is possible to already SSH into machine B, but I usually add the following entry to the config
in the .ssh
directory. If the file is not there already it can just be created.
Host macb
HostName <hostname or IP>
User <youruser>
IdentifyFile ~/.ssh/macb
Everything has been setup now and it is possible to use SSH to connect to machine B from machine A.
ssh macb
That’s it! I hope this was useful for you.
Thank you for reading!
- If you enjoyed this, please follow me on Medium
- Buy me a coffee to keep me going
- Support me and other Medium writers by signing up here