4

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?

  • and what address is the Mac using? ifconfig will show – Milliways Jun 20 '14 at 0:34
  • local address is 192.168.1.6 – KamikazeStyle Jun 20 '14 at 2:03
  • Do you see an entry like bridge100: 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. – Milliways Jun 20 '14 at 3:51
  • I have a bridge0? I am connected to the network via wifi from my mac, I tried sharing both from wifi to ethernet and from ethernet to ethernet(from mac to pi network) and nothing so far. I can ssh from a ethernet coming from my router but I need that jack for my desktop for work which is why im trying to do it this way – KamikazeStyle Jun 20 '14 at 5:15
  • I wonder if you could get this to work by assigning static IPs on both ends? I have configurations for that if I need to move things between my linux boxes when there is not network available. – Chris Stratton Feb 24 '15 at 0:13
1

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 pi@NamePi.local

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 Jun 21 '14 at 14:06
4

Just use ssh pi@raspberrypi.local

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 Jul 15 at 22:09
1

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 mymacuser@192.168.2.1 -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 mymacuser@192.168.2.1 -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.

1

Once you had shared your connection and connected your mac and your pi display your routing table :

enter image description here

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 pi@192.168.2.x
0

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.

0

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 pi@192.168.2.2.

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 Jul 6 '17 at 8:10
  • Edited to include more info. – James Owers Jul 6 '17 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.