TheodoreLogan
Posts: 2
Joined: Tue Dec 25, 2018 3:43 am

SSH Only Works After "Service SSH Restart"

Thu Dec 27, 2018 4:38 am

Here is the short version of my issue with details included below:
I changed the SSH port on my Pi and now after rebooting or power cycling, SSH will only work if I run

Code: Select all

sudo service ssh restart
.

This is my first Pi and my experience with Linux is zero, so please assume I know nothing when writing your response :)
Thanks in advance!

Details:
Pi Info
Hardware: Raspberry Pi 3 B+
Software:
* PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
* NAME="Raspbian GNU/Linux"
* VERSION_ID="9"
* VERSION="9 (stretch)"
* ID=raspbian
* ID_LIKE=debian
Checkin SSH is On: Yes
IP: 192.168.1.126

Computer Info
Macbook Pro
OS: El Capitan
IP: 192.168.1.73

Router Info
Manufacturer: ARRIS
Model Number: BGW210-700
Software Version: 1.7.17
Hardware Version: 02001C0046004D

ISP
AT&T

Steps Taken
First tried to connect to Pi through MacBook using:
“ssh pi@192.168.1.126”
received message:
“ssh: connect to host 192.168.1.126 port 22: Connection refused”

On router, tried to forward port 22 to PI. Received message:
“The port range 22-22 in the service conflicts with the reserved port 22”
Info on the web indicates AT&T has started blocking this port.

Changed SSH port on Pi to 6522 by editing:

Code: Select all

sudo nano /etc/ssh/ssh_config

Restarted SSH service on Pi:

Code: Select all

sudo service ssh restart

On router, forwarded port 6522 to Pi.
On MacBook I ran "ssh pi@192.168.1.126"
It worked!

Powered off Pi using

Code: Select all

sudo halt

Powered on Pi, attempted to connect through MacBook using:
“ssh pi@192.168.1.126”
Received message:
“ssh: connect to host 192.168.1.126 port 22: Connection refused”
I can still ping the Pi from the MacBook.

On Pi I ran:

Code: Select all

sudo service ssh restart

On MacBook I ran "ssh pi@192.168.1.126"
It works again!

If I Reboot or power down/up Raspberry Pi, SSH stops working. I receive the message:
“ssh: connect to host 192.168.1.126 port 22: Connection refused”
If I restart SSH service, it begins working again.

fbe
Posts: 494
Joined: Thu Aug 17, 2017 9:08 pm

Re: SSH Only Works After "Service SSH Restart"

Thu Dec 27, 2018 10:23 pm

Why did you edit /etc/ssh/ssh_config? This is the client configuration, not the server configuration.

Try

Code: Select all

sudo systemctl enable ssh
sudo systemctl start ssh
or use raspi-config (command line interface) or Raspberry Pi Configuration (desktop application) to enable the ssh service.

TheodoreLogan
Posts: 2
Joined: Tue Dec 25, 2018 3:43 am

Re: SSH Only Works After "Service SSH Restart"

Fri Dec 28, 2018 1:47 am

Why did you edit /etc/ssh/ssh_config? This is the client configuration, not the server configuration.
That was unintentional. I didn't look closely enough at the webpage I used as a reference and edited ssh_config instead of sshd_config.

Also, I realized that SSH was not enabled as I thought. I believed it was enabled because I checked the setting after running "sudo service ssh restart". So after rebooting or power cycling, the setting would revert back to the disabled default.

I changed the ssh and sshd port back to 22 and enabled SSH in the preferences: issue resolved.

Return to “Beginners”