I am trying to set up an ssh connection from my mac terminal to my raspberry pi. I have already connected to a monitor and have ensured that the SSH is enabled. I have my raspberry pi’s ip, and it is connected to the same network as my macbook. I have also enabled remote login on my mac, and it does appear to be trying to connect with port 22, which from my research appears to be what I need to be doing. However, when I typed in the command in my terminal, ‘ssh pi@<Pi’s IP address>’, using my pi’s ip address, it returns saying that ‘connect to host port 22: connection refused’.
Does anyone know any reason why this would still be occurring? Or, if not, does anyone have a way with which I can make the code I am trying to use run on startup instead of having to enter the command in the terminal, which is why I was trying to make it headless and not have the monitor - the project is for a robot, which I am trying to control and have camera video from a web browser.
Thanks for including such detailed troubleshooting steps confirming what you’ve already tried.
There are a few common pitfalls for SSH headless connection the main ones being not enabling SSH on the Pi, the Pi not yet having a user defined and stalling at the login/create user screen (this catches most headless users).
If the Pi has fully completed the boot process then we can rule those options out.
Are you able to ping the Raspberry Pi from your Mac successfully? Even if you can’t get a SSH connection established?
I haven’t personally tried to use the built in SSH tool on a Mac, I’ve always used Putty from Windows, so perhaps there’s an issue there which is preventing the connection.
Have you been able to use your Mac to connect using SSH to a different device? Just so we can determine if that half of the connection is behaving normally.
As far as running a script or program on startup, there are actually heaps of different ways to do that in Raspberry Pi OS. Each method will have pros and cons, this guide below covers 5 different methods.
Yes, I’m able to ping the raspberry pi from my mac, but I can’t say whether it’s a problem specifically with the mac’s connection because I’ve never tried to connect anything with SSH before.
If you can ping your Pi but the connection is refused it may indicate that your network may not allow direct SSH connections between devices. This is common for eg. a publicly configured network, since you wouldn’t want connections between users in eg. an airport or cafe.
What network are you working on? Is it your home network or an enterprise network?
I’m currently using my home network