I am trying to ssh into pi from my mac's shared ethernet connection. I connected the two and turned on internet sharing (both ethernet to ethernet and wifi to ethernet). To find the assigned ip I have used cat /private/var/db/dhcpd_leases
from the mac terminal shown here http://www.interlockroc.org/2012/12/06/raspberry-pi-macgyver. This brings up
name=fbi ( What i changed my network name on pi to be lol)
ip_address=192.168.2.3
lease=0x53a46359, ect.
so I know it is there, however when I try to ssh to it my connection times out. I've tried nmap'ing it from mac terminal and nothing shows up. I have also tried ping'ing that address and to no avail. Why is that address showing up on the mac dhcpd leases but not work when ping'ing to it which I am assuming is the reason I cannot ssh to it?
6 Answers 6
I have tried many different methods of directly connecting the Pi to a Mac, with limited success.
It really depends on what you are trying to achieve.
Enabling Internet Sharing
works (similar to the method you tried), but only if connected to a router.
This seems of limited value - you might as well plug the Pi into a router.
I enabled ipv6
on my Pi running Raspbian and can connect from OS X using ssh
. (Append ipv6
to /etc/modprobe
to enable ipv6).
Connect from OS X using either ssh pi@fe80::ba27:ebff:fe19:5b37%en0
or more easily as ssh [email protected]
Unfortunately netatalk
and tightvncserver
on the Pi cannot connect via ipv6, although these work using ipv4. (It may be possible using IP tunneling).
A third possibility occurred to me; implementing DHCP
on the Pi, but I have never tried it.
-
I'm runnning command line so i don't have a desktop environment to stream so this seems perfect thank you.KamikazeStyle– KamikazeStyle2014年06月21日 14:06:11 +00:00Commented Jun 21, 2014 at 14:06
-
I had to
ifconfig
on my Mac and try different interfaces, which turned out to been4
otherwise this answer worked when Internet Sharing didn't. Thanks!Stephen Gilboy– Stephen Gilboy2022年01月17日 19:49:22 +00:00Commented Jan 17, 2022 at 19:49
Just use ssh [email protected]
Connect an Ethernet cable from the Pi to your Mac, using an adapter if necessary. No crossover cable needed.
See Connect directly to Raspberry Pi from Mac over Ethernet.
-
After messing around with other suggested solutions (and never finding the bridge100 entry mentioned by some of those solutions), this is what worked for me. Wish I had tried it first.Grant Petty– Grant Petty2019年07月15日 22:09:36 +00:00Commented Jul 15, 2019 at 22:09
-
Links dead, but here's the archive: web.archive.org/web/20180531222305/http://timemachines.io/blog/…Cam.Davidson.Pilon– Cam.Davidson.Pilon2022年04月03日 14:13:31 +00:00Commented Apr 3, 2022 at 14:13
Here's a solution I came up with. Basically, the problem is that when you directly attach, the Pi has no internet if Internet Sharing is turned off, but the Mac can't access the Pi if Internet Sharing is turned on. (The Pi can access the Mac at 192.168.2.1, however.)
Either of these could be solvable if the Mac provided interface bridging (which it does in 10.9+, but it doesn't really work with WiFi, which I need), or port forwarding for its NAT using Terminal (which I've had no success with, and apparently completely changed from natd to pf in Mountain Lion).
So what I did is create a remote forwarding SSH tunnel, since the Pi can see the Mac. it is created when the Pi starts up and is attached to Mac ethernet with Internet Sharing turned on.
(To set this up, the Pi serial console, but a screen+keyboard would have worked just as well; I probably could have also used SSH to get into the Pi if Internet Sharing was turned off.)
change the default SSH port on the Mac, by editing /etc/services and changing the SSH line to TCP port 43188 (note: this means you have to use -p22 when connecting to normal SSH servers) [This is optional, but provides added security than using the default port 22.]
turn on Remote Login on my Mac in Apple Menu->System Preferences->Sharing. (If it was already on, then cycle it so it uses the new port.)
create a public/private keypair for SSH, with no passphrase:
ssh-keygen -N ""
copied the public key (id_rsa.pub) into ~/.ssh/authorized_keys on my Mac
copied the private key into /home/pi/.ssh/id_rsa on my Pi
made sure I could SSH from the Pi to my Mac, without a password prompt, as root:
sudo ssh [email protected] -p43188 -i /home/pi/.ssh/id_rsa
- added this line to /etc/rc.local on the Pi, before
exit 0
:
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p43188 -N -R2222:localhost:22 [email protected] -i /home/pi/.ssh/id_rsa &
Now, when I start up my Pi, and it's attached to my Mac via Ethernet and Internet Sharing on the Mac is turned on, it creates a remote forwarding tunnel in which when my Mac gets traffic on port 2222, it forwards it through the tunnel to the Pi's port 22. So I can type:
ssh -p2222 pi@localhost
And bingo, I'm in.
Once you had shared your connection and connected your mac and your pi display your routing table :
The ip will certainly be somethings 192.168.2.X and you can know it's you pi by his MAC address.
Once you know the IP address simply log in with SSH
ssh [email protected]
Suppose you have set up your pi with a static ip address like 192.168.0.50 The first two numbers (192.168) represent your network address and the last two (0.50) are the 'subnet and host' numbers of the pi. If you try to connect by ssh with ethernet from the mac, the ip address of the mac must have the same network number 192.168, the same subnet number 0 but a different number for the host. In this case you might use 192.168.0.40 for the mac's ip. You can set this up using the Network icon on your mac's System Preferences panel using 'Configure iPv4: using DHCP with manual address', for example, on the ethernet settings.
First, use sudo raspi-config
to enable ssh access. Then you must configure your mac to do internet sharing via ethernet (system settings> sharing). You should now be able to ssh [email protected]
.
Full details with screenshots here: https://mycyberuniverse.com/mac-os/connect-to-raspberry-pi-from-a-mac-using-ethernet.html
-
Please do include the relevant information from the link in the answer. This is to prevent link rot.Bex– Bex2017年07月06日 08:10:29 +00:00Commented Jul 6, 2017 at 8:10
-
Edited to include more info.James Owers– James Owers2017年07月06日 12:30:36 +00:00Commented Jul 6, 2017 at 12:30
ifconfig
will showbridge100: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
This will only appear if the Mac is connected to a network. I suspect that you can only contact (and thus ping) if you have a router/network connected.