ethanic
Posts: 31
Joined: Tue Jul 14, 2020 5:37 am
Location: San Francisco Bay Area, California

SSH/sudo is broken

Fri Jun 09, 2023 8:24 am

I've set up my Pi and have had it running for a while now but for some reason, I can't SSH into it anymore nor use sudo. I set up PiTunnel and for some reason I can still access a remote terminal/SSH through there but if I try SSH-ing anywhere else (Windows Terminal, my iPad, phone, etc.) it gives me an error saying

Code: Select all

ssh: connect to host serverpi port 22: Connection refused
I tried editing the SSH settings through the piTunnel remote terminal but apparently sudo doesn't work anymore either giving me this error:

Code: Select all

sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
One thing of note is that before all of this I couldn't write files to my Pi over Windows network share so I ran sudo chmod 755 / under root to try and give myself full access to the drive. I didn't really know what I was doing and looking back I could have just set up something like Samba but I'm guessing that's what caused the sudo & SSH issues.

User avatar
kerry_s
Posts: 6040
Joined: Thu Jan 30, 2020 7:14 pm

Re: SSH/sudo is broken

Fri Jun 09, 2023 9:19 am

I ran sudo chmod 755 /
your screwed time to reinstall.

User avatar
rpdom
Posts: 22378
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: SSH/sudo is broken

Fri Jun 09, 2023 10:55 am

ethanic wrote:
Fri Jun 09, 2023 8:24 am
so I ran sudo chmod 755 / under root
That command wouldn't break anything.

This one, however...

Code: Select all

sudo chmod -R 755 /
would mess up the permissions on lots of files and directories.

You could try installing a new OS on another card, then use that to mount the old card and go in and correct the permissions - but good luck finding them all.

Best option is to install a fresh OS and copy your work over to it. Then take a backup so you can recover next time you make a mistake. (we all make mistakes. That's one of the reasons we do backups)
Unreadable squiggle

ethanic
Posts: 31
Joined: Tue Jul 14, 2020 5:37 am
Location: San Francisco Bay Area, California

Re: SSH/sudo is broken

Fri Jun 09, 2023 11:38 am

rpdom wrote:
Fri Jun 09, 2023 10:55 am
ethanic wrote:
Fri Jun 09, 2023 8:24 am
so I ran sudo chmod 755 / under root
That command wouldn't break anything.

This one, however...

Code: Select all

sudo chmod -R 755 /
would mess up the permissions on lots of files and directories.

You could try installing a new OS on another card, then use that to mount the old card and go in and correct the permissions - but good luck finding them all.

Best option is to install a fresh OS and copy your work over to it. Then take a backup so you can recover next time you make a mistake. (we all make mistakes. That's one of the reasons we do backups)

fu**. you live and you learn I guess lol. reinstalling everything as we speak, though I am curious is there something similar to Windows File History on RasPiOS? Like it takes hourly snapshots/backups everything to an external drive & whenever something like this happens, I could just restore to a earlier snapshot/backup.

User avatar
GTR2Fan
Posts: 1968
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: SSH/sudo is broken

Fri Jun 09, 2023 12:30 pm

ethanic wrote:
Fri Jun 09, 2023 11:38 am
...is there something similar to Windows File History on RasPiOS? Like it takes hourly snapshots/backups everything to an external drive & whenever something like this happens, I could just restore to a earlier snapshot/backup.

Not natively in the same way Windows does as far as I know, but you can use Raspberry Pi OSes SD Card Copier whenever you like.

I wouldn't trust the Windows method anyway as, in my personal experience, it's very rarely entirely recovered an install from a major PEBCAK disaster.

Backups are your friend, but I've had backups fail too, so make a backup of the backup as a backup isn't a reliable backup until it's backed up.
Pi4B 2GB Rev1.4 Mini-PC/Media Centre: ARM=2.25GHz @1.1v, Core=600MHz, GPU=850MHz. Raspberry Pi OS with KODI on 128GB Sandisk Extreme Pro A2 microSD card in Integral card reader in USB3.0 port (138MB/s read). Geekworm P173 case with copper shim on SOC.

User avatar
rpdom
Posts: 22378
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: SSH/sudo is broken

Fri Jun 09, 2023 1:42 pm

GTR2Fan wrote:
Fri Jun 09, 2023 12:30 pm
Backups are your friend, but I've had backups fail too, so make a backup of the backup as a backup isn't a reliable backup until it's backed up.
The method we used to use, back in the old days of mainframes with removable disk packs, was to copy the system to another disk, then shutdown and swap the disk over. This way we tested that the backup had worked correctly and we had a known good system stored away in a safe place.

The same method can be used with the SD cards. Rotating through a series of "spare" disks/cards will mean you have older backups in case of serious failure.

The rotation we used was a bit more complex than that with copies on several sets of tapes as well.
Unreadable squiggle

ejolson
Posts: 11333
Joined: Tue Mar 18, 2014 11:47 am

Re: SSH/sudo is broken

Fri Jun 09, 2023 2:44 pm

GTR2Fan wrote:
Fri Jun 09, 2023 12:30 pm
ethanic wrote:
Fri Jun 09, 2023 11:38 am
...is there something similar to Windows File History on RasPiOS? Like it takes hourly snapshots/backups everything to an external drive & whenever something like this happens, I could just restore to a earlier snapshot/backup.
Not natively in the same way Windows does as far as I know, but you can use Raspberry Pi OSes SD Card Copier whenever you like.
What used to pass as the native Unix backup is dump.

https://man.netbsd.org/dump.8

The dump multi-level backup system is included with most Linux distributions. In Raspberry Pi OS it may be loaded by

# apt install dump

Usually people write a simple script to automate when each dump level is used. It works just as well with hard disks for the backup media as tape.

More recently I've been using rsync to copy files to a snapshotable copy-on-write filesystem such as BTRFS. Details about this are at

viewtopic.php?p=1348105#p1348105

There is also a thread about scripts to make incremental backups to archived images of SD cards at

viewtopic.php?t=332000

The author of those scripts has been answering questions and maintaining those scripts for a long time.
Last edited by ejolson on Fri Jun 09, 2023 4:06 pm, edited 1 time in total.

User avatar
rpdom
Posts: 22378
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: SSH/sudo is broken

Fri Jun 09, 2023 4:03 pm

ejolson wrote:
Fri Jun 09, 2023 2:44 pm
What used to pass as the native Unix backup is dump.
Some of use still use it :)
Unreadable squiggle

timrowledge
Posts: 1432
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island

Re: SSH/sudo is broken

Fri Jun 09, 2023 6:06 pm

Duplicity works pretty well for me. You can configure it to run on whatever schedule you want.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

ejolson
Posts: 11333
Joined: Tue Mar 18, 2014 11:47 am

Re: SSH/sudo is broken

Sat Jun 10, 2023 2:21 pm

timrowledge wrote:
Fri Jun 09, 2023 6:06 pm
Duplicity works pretty well for me. You can configure it to run on whatever schedule you want.
I find it interesting that duplicity doesn't support hard links. Are you backing up to cloud storage or a local disk?

Return to “Beginners”