r/linuxquestions • • Sep 04 '20

Accidentally ran "sudo chmod -R +x /"

Had a total brain fart and ran the above command, intending to enable all files in my current directory executable. Instead I recursed over the whole file system.

Got a lot of "<path> : Operation not permitted" measages but I still definetly ran it under sudo.

How bad is this? Like re-install bad?

Update:

Thanks all for the info and words of encouragement to let this be a lesson haha.

FYI it was on an OEM IoT logging device that I was adding some functionality too before we deployed it to a site. So I didn't actually have any of the software to do the installs and the OEM doesn't release the images. However the manufacturer is sending out a replacement drive with a new image on it free of charge (lucky).

Oh and I've learnt to take image backups of my other devices before modifying them now.

133 Upvotes

113 comments sorted by

9

u/aaronryder773 Sep 04 '20

+x is for executable what -R for?

9

u/[deleted] Sep 04 '20

Well recursive, but yes, I didn't need to use that (in hindsight)

3

u/aaronryder773 Sep 04 '20

ahh quite obvious and yet I had to ask.

3

u/[deleted] Sep 04 '20

Today you learned! Don't be afraid of that.

3

u/furrowed_rhino Sep 04 '20

well, the mistake wasn't the -r option, it was the / instead of .

1

u/cdp1337 Sep 04 '20

I've done that before. chmod a+rX pub/ -r

Then spend a few seconds starring blankly at the screen as to why apache can't read the files before I realize what I did.

1

u/Pixels_128 Sep 05 '20

recursive. basically, it loops through all of the files inside the selected directory. So what it did was made all of the files under / executable

18

u/captainstormy Sep 04 '20

Huh, yeah.....

Like the other poster I wouldn't be surprised if nothing actually broke from doing that. But obviously it's not right to run a system like that.

Assuming you don't just have a prior snapshot to revert to or some other form of fallback plan in place before this happened this is definitely a reinstall it is easier kinda thing.

But this is a good teachable moment. You should have a system in place that lets you get up and running from a fresh install super easy.

For me, that system is to keep /home on a separate partion (though it would be affected as well, so you should restore it from a backup), and make regular backups of that.

Then I have a script that does all of my setup and configuration I can run after a fresh install. Then just a quick edit to fstab and dnf.conf and I'm back in business.

Make regular backups of your home drive and store them external to your main computer.

At home I don't worry about any type of fallback plan to fix/restore my system because getting up and running from a fresh install is like a 5 minute process for me. On a work machine that would be a different case.

4

u/[deleted] Sep 04 '20

Thanks. Yes I'm fairly new to diving around in the cmd line as I was working on a machine over ssh.

Pretty sure I'll learn from this now.

1

u/ccAbstraction Sep 04 '20

Do you have any suggests for making back ups if you don't have an external drive or cloud storage? I just have my most important files sync'd to my laptop with Syncthing. If something bad happens I switch off the problematic system and make sure Syncthing sees the still good files as newer.

1

u/captainstormy Sep 04 '20

Without an external HDD or cloud storage that's probably really all you can do.

I'd suggest getting an external drive (or even better a NAS) when your able. Off-site/cloud backups depend on how important your files are to you in case of fire or thieft.

2

u/as96 Sep 04 '20

Since you haven't removed permissions everything should still work but security wise it's bad.

I would reinstall just to be safe.

2

u/[deleted] Sep 04 '20

Yeah ssh isn't working now. Googling it up now I see I'm not the first to do this haha. Looks like I have to reset the ssh key file permissions to read

2

u/nimraynn Sep 04 '20

With things like this, you almost certainly won't ever be the first to do it... and you won't be the last. All part of the learning curve!

45

u/quiet0n3 Sep 04 '20

It's fine you took a backup before making changes right?

Lol

It's not horrid, it's a pretty big security issue but apart from that nor horrible.

Apparently a lot of package managers have support for reinstalling all packages and that should solve a lot of the biggest issues.

Apparently rpm systems have a rpm --setperms option as well.

So yeah depending on how critical the system is I would reinstall.

5

u/Blutfalke Sep 04 '20

Pacman definitely supports it too

5

u/beermad Sep 04 '20

Boot with rescue media (such as an installation USB) and restore it from your latest backup.

5

u/aoeudhtns Sep 04 '20 edited Sep 04 '20

If you're running a RedHat family distro, i.e. Fedora, openSUSE, CentOS, RHEL, etc. - you can fix it pretty easily.

# rpm --setperms <package> does the job.

To do your whole system:

# for x in $(rpm -qa); do rpm --setperms $x; done

Edit: you still will have to manually correct locations outside of RPM package control, notably your home dir. But it's unlikely you have much of anything +x in your homedir, so you can do a recursive -x there and then fix the few things that need it: find /home/UpsetRain -type f -exec chmod -x {} \;

3

u/[deleted] Sep 04 '20

Yeah, I thought I remembered RH having a quick fix for this kind of stuff. Thanks for the refresher.

4

u/[deleted] Sep 04 '20

This thread makes me want to back up again. Brb...

1

u/eellikely Sep 04 '20

Your backup isn't automated?

1

u/Pixels_128 Sep 05 '20

That's a thing?

1

u/[deleted] Sep 05 '20

Nope. I only have one external HDD that I bought years ago and I use it to store movies and other crud that I don't want to delete. It doesn't have enough space to store a backup as well.

Not to worry though, I just ordered another one!

7

u/ssh-bi Sep 04 '20

If it's a single user system, the security risk is less. But you will experience unexpected behaviours from time to time. When the time is right, I would reinstall the last version of the distro, copy my data and move on.

Even though you ran with sudo, you cannot change permissions on files of some special file systems such as, procfs and so on.

6

u/PM_ME_SOME_MAGIC Sep 04 '20

Small knit: you recurred over the files; recursing is what happens when you make a witch angry again.

3

u/AlexAegis Sep 04 '20

I once did something similar and removed every symlink from / recursively. I have a little script that removes dead symlinks, I tweaked on it and had the genius idea to try it out on / because there's no way that little tweak could possibly break it.

Reinstalled. Thankfully my self-setup scripts are pretty good so I was back in track a few hours later, most of that time was just the install itself and watching my script run.

3

u/[deleted] Sep 04 '20

apt-get --reinstall install dpkg --get-selections | grep install | grep -v deinstall | cut -f1

There may be some directories in or just under / that need fixing manually, most of stuff there already has x permission anyway.

A soon as i saw this post I remember on SCO Unix and Xenix 30yrs ago had a command to do this from package catalog "fixperm". I must be old

3

u/eellikely Sep 04 '20

Restore from your backup.

2

u/SoggyMcmufffinns Sep 04 '20

Highly recommend keeping some daily backups. Maybe some weekly/monthly as well. At any point you can be back and running in a couple of mins usually from a quick snapshot. Backups can be automated as well. I wouldn't want all my files executable personally for many reasos, but technically it may stll function. I just recommend the backps in the future as it's not only good for just about any OS regardless, but makes it easy to just revert from a backup, learn, laugh, and be on your way.

Only took me deleting my entire dive with everything on it before to always carry a backup lol. That and a bootable USB. Highly recommended my friend.

2

u/theunwisegeek Sep 04 '20

At least it wasn't 'rm -rf /' instead of 'rm -rf .' I've done that before and it's as terrifying as you might think. :)

This is security breaking, but you have plenty of time to back up. If you use SSH to get into the machine, you'll want to make it a point to reenable passwords temporarily and only until you fix the permissions on your authorized_keys file.

Definitely do a reinstall though. There's no telling how silently something can fail in this condition.

On the bright side, this could be a cool opportunity to try a new distro if this is your computer.

Either way, have fun!

2

u/costagabbie Sep 04 '20

well at least you didn't accidentally ran "sudo rm -rf / --no-preserve-root"(This will recursively delete everything it can, so not a good idea to run it) i'm not an expert but personally i would just reinstall, or go back to a previous snapshot.

2

u/voicesinmyhand Sep 04 '20

Well probably everything will be fine. "Executing a jpeg" is obviously crash territory, but who does that on a regular basis?

2

u/veryusermuchwow Sep 04 '20

A client scheduled an update for their server outside of their business hours. I had things come up but since I'd already committed to doing that, decided to go ahead with it at 3am. Soon I realised my user had no write permissions and couldn't update the clones. but I really needed to update then (for whatever reason I convinced myself it had it be done) so I started searching for exploits.... brute forced my way into another user's account with nopassword sudo perms to a certain python CLI tool. great-o. I used that to get root access so that I can change perms for my user....but well...I accidentally revoked execute permissions recursively from /. a seconds' delay of cancelling the operation was enough to change perms for sudo, chmod....EVERYTHING. I thought maybe all of this is a dream. I'll just logout and come back in again. here we get to brainfart2. shouldn't have done that. now nobody could login remotely.

we had to get in touch with their engineers in the morning and setup a new server and migrate all their data there. ended up sleeping at 11. and this was my fourth month working here, (and having a job...ever). glad my seniors were "chill" about it and told me not to beat myself up about this.

:)

2

u/NuBZs Sep 04 '20

Sure are a lot of people raised on windows in this thread.

There is no reason to reinstallthe entire os FFS!!!

1

u/jackass_in_a_hoodie Sep 04 '20

Feel free to present an alternative option lmao

1

u/NuBZs Sep 04 '20

As far as wiping it all first I mean.

2

u/pythonbashman Sep 05 '20
  1. Restore from backup.

  2. Reinstall and learn from mistakes.

  3. The best path:

    1. Unplug Machine

    2. Take outside

    3. Join the other IT professionals around the pyre

    4. Throw your "mistake" on with the others

    5. Celebrate your new freedom

    6. Avoid eye contact with the boss until any and all guilt has subsided.

2

u/tylerl852 Sep 04 '20

This is why I backup my system

0

u/ragger Sep 04 '20

intending to enable all files in my current directory executable

Why did you need to use sudo for this?

1

u/[deleted] Sep 04 '20

I had just been using it for something else. In hindsight I may not have needed it. Fairly noob to linux in general and didn't realise the damage I could do. Will use sudo sparingly from now

1

u/ragger Sep 04 '20

If you don't mind, what were you trying to do? Why did you want to make everything in a folder executable?

1

u/[deleted] Sep 04 '20

I had some bash scripts which I had just ftd over from windows and they didn't have x permission. The folder just had the scripts in ot so I thought I'd save myself a HUGE amount of effort haha.

2

u/deong Sep 04 '20

There's a principle of least privilege that says you want every user/application/whatever to have the fewest privileges it can have and still work. The same general principle applies to things like this. If you have a directory full of bash scripts you want to make executable,

$ cd folder
$ chmod +x *.sh

is better than

$ chmod -R +x folder

The former can only ever act on files in the folder directory that end in .sh. The latter can recursively descent into a subdirectory you might not have noticed being there, and it will make files other than *.sh files executable if they happen to be there.

Generally, favor methods that limit the scope of their action to only what you want rather than more general methods that will do what you want only if what you happen to run them on is what you meant and expected.

3

u/shiratek Sep 04 '20

I would guess because they didn’t have sufficient permissions on the current directory.

3

u/ragger Sep 04 '20

I wanted to get some background info on this so OP could avoid this issue in the future. You'd be surprised how many use sudo to perform actions in their own home directory.

0

u/[deleted] Sep 04 '20

[deleted]

2

u/deong Sep 04 '20

Yep. Sudo makes you root, and you only want to use it when you need to be root, which generally means permissions on files. In your home directory, you own everything. Using sudo is probably unnecessary, and can end up creating files that your user can't read, which probably isn't what you want either.

1

u/[deleted] Sep 04 '20

Probably working in /usr/bin or /usr/local/bin or something like that

1

u/AquaL1te Sep 04 '20

Best choice is to reinstall, yes.

If you have Fedora you can see the damage with e.g. rpmverify / rpm -V. Or something equivalent on another distro. But the only way to fix this properly is to reinstall.

1

u/[deleted] Sep 04 '20

Ouch. I will remember this as a good textbook example on the dangers of sudo :)

Yeah. Probably a reinstall. :(

1

u/[deleted] Sep 04 '20

:(

1

u/furrowed_rhino Sep 04 '20 edited Sep 04 '20

For anybody not already using it AIDE creates a database of all files, including their permissions and md5, that allows you to easily fix situations like these.

also, for anybody in need to give sudo permissions to other people on their servers, there are extensions to sudo, both python and C I believe, that allow you to limit the commands people can execute, we have python thinghies that check for any comands run against / and stop it, you very rarely need to do that and more often than not it's a mistake, when you actualy do need it it's ok to have to ask for the actual root account to the sysadmin.

1

u/jksinton Sep 04 '20

It doesn't really seem that bad to me. Not ideal, but not game over. You just added executable permissions to files and search permissions to directories at the user level. I would look at restoring the permissions instead of reinstalling. It will be a great learning experience on the ins and outs of the linux filesystem.

1

u/polypagan Sep 04 '20

MacOS used to have a disk manager function that restores permissions over the entire filesystem. (And every time I used it, it made some changes.)

Seems to me it would be possible to create something like that for Linux. Likely it would be distro- (or distro family-) dependent.

1

u/Spicy_Poo Sep 04 '20

What distro?

1

u/ZaitsXL Sep 04 '20

That highly depends on where you ran this. If that was production grade server then you're screwed, if that was just your personal laptop you can live with this

1

u/wwdillingham Sep 04 '20

Its a lot better than -x

1

u/davidgarazaz Sep 04 '20

List your installed packages and take note, backup your home folder, and reinstall.

1

u/ive_got_a_boner Sep 04 '20

One of the beautiful things about Linux is you can reinstall anytime without having to deal with licenses. I suggest taking notes of any special modifications you’ve made to your system, and keeping all your personal files (pictures, music, etc) in one folder which you rsync to a backup drive regularly via cronjob. Steam, games, applications can all be easily reinstalled so don’t worry about them. And be super careful when using chmod, rm, etc. one trick is to use “ls” first, i.e. ls-R / to see which files are affected.

1

u/lostcluster0 Sep 04 '20

If you use gentoo, simply run emerge -e @world

1

u/gardotd426 Sep 04 '20

Actually, you should be able to just reinstall all your packages which will replace the files. pacman -Qnq | pacman -S -

1

u/Tetmohawk Sep 04 '20 edited Sep 04 '20

Yes, you probably need to reinstall. In particular, files that were once readable now get executed.

It does depend on what your computer is for. If it's for personal use then just reinstall and revert your personal files with the find command below. If it's a mission critical server that you can't fix quickly, then there are some tools you can use. I'll briefly describe those now.

(1) You can run something like find / -ctime -7 -type f -perm 771 -execdir chmod 660 {} + to convert something that was modified in the last seven days back to 660 when it is now 771. The -ctime switch looks for files whose metadata (like permissions) were changed within the last few days. 7 would mean exactly seven days, -7 means within the last seven days, and +7 would mean more than seven days ago. The -perm switch is exact so you may need to do sever iterations of it for specific file permissions. The -execdir switch will be used to change the permissions.

(2) You can run rpm -V to see if a specific file has changes. Then use rpm to reinstall as needed. Actually, you might just want to get a list of rpm packages that are installed and do a forced reinstall of the files, but not the config files.

While you will still probably want to reinstall, the find command is great for changing back your personal files. Run the following two commands: find /home/me -type f -execdir chmod 660 {} + and find /home/me -type d -execdir chmod 750 {} +.

And just so you don't feel so bad, I did this once on a Solaris NIS-NFS cluster. Some lessons are learned the hard way . . .

1

u/Parker_Hemphill Sep 04 '20

You're best off doing a fresh install, but if you have time to burn and are bored you could try doing a re-install of all packages installed. In Debian based distros you could try something like:

sudo apt install --reinstall $(sudo apt list --installed|awk -F'/' '{print $1}'|tr "\n" " ")

Then something like:

for list in $(ls /home); do sudo chown -R ${list}:${list} /home/${list}; done

I HIGHLY recommend you do a fresh install but I'd be interested in hearing how this method works.

EDIT: Stupid autocorrect of "distro" to "distress"

1

u/The_camperdave Sep 04 '20

Can you read the permissions from your backup and apply them to the live files? I'm sure someone can script that.

1

u/[deleted] Sep 04 '20

For these moments you want regular full system backups. Get ya self a 2TB SSD and back hour backups, Cronopete looks pretty good for a GUI solution I haven't used it myself.

For your current problem, copy anything important data to external storage and reinstall the whole OS. It's going to take you forever to fix each folder, and then each folder and file in those folders. Reinstall is the quickest and easiest solution.

1

u/john-of-the-round Sep 05 '20

no. reboot using install cd/dvd enter as root and rerun chmod correctly.

0

u/[deleted] Sep 04 '20

For starters, sudo chmod 755 -R /etc Then I'd make all .service files not executable. IIRC systemd throws warnings and potentially errors with executable service units.

0

u/[deleted] Sep 04 '20

[deleted]

10

u/[deleted] Sep 04 '20

Though I wouldn't be surprised if it technically didn't break anything..

Yeah I assumed as much. But you're right, best to start over haha. Bugger.

8

u/taostudent2019 Sep 04 '20

A few very wise programmers told me to get good at starting over. Take insane notes, make them readily available. Put everything right there to do everything from scratch all over again.

It used to take me a full day, now I have it down to 1 hour on basic stuff and 3 hours for my most complicated live server. And everytime I do it, I update the instructions to make it a faster process.

There are a lot of good reasons to do this!

3

u/esunabici Sep 04 '20

Next step: automate it with a configuration management system

4

u/taostudent2019 Sep 04 '20

Yes! Awesome!

I have a tiny company, usually only a few engineers on a project. But it is mostly me. Everytime I get downtime I try to move some aspect of our set up to be more like the big boys.

Some of it is super basic stuff, but someone has to do it. And some of it is a little trickier and it takes a few attempts to get it right.

I guess I can put this on the list.

:D

2

u/esunabici Sep 04 '20

You said you document your changes, so you can look at this as a specific format for your documentation. Your documentation just happens to be executable and puts the system in the desired state.

1

u/taostudent2019 Sep 04 '20

I like it! I like every bit of it.

I think I could almost put the whole thing in a shell script. My notes are extremely clean.

2

u/esunabici Sep 04 '20

This is a few steps ahead of shell scripts. They detect the state of the system and determine what needs to be done to bring it to the desired state. If there are no changes, it does nothing. They can also report of differences which can show undesired changes.

1

u/taostudent2019 Sep 04 '20

Okay, I figured as much.

2

u/Parker_Hemphill Sep 04 '20

Two big things can help you with that.
1: SaltStack for building a reliable and easy method for maintaining services.

2: Move as many workloads to docker containers as you can. I have a separate partition holding all my persistent volumes and have it down to a simple re-install of my OS and then docker, docker-compose. Takes about 30 minutes of effort to lift and shift to a new distro. At work we use salt to push new configs and keep our preprod/prod stacks in-sync. (Other teams like to try and make local changes to try things. Salt blows away any unapproved changes)

1

u/taostudent2019 Sep 05 '20

Awesome input! Someone else suggested Salt Stack.

I've been looking into it.

2

u/Parker_Hemphill Sep 05 '20

And salt is Python backed. (So is ansible)

We use salt on EC2 instances and can teardown an instance and stand up a fully configured replacement in about 20 mins with just some clicks in the AWS console.

EDIT: I'd also throw chrony into the mix as a good tool to keep your services healthy. chrony will restart them for you

1

u/taostudent2019 Sep 05 '20

Okay!

Awesome. I'm also on AWS. I'm learning and reading as people share this information.

I appreciate your help!

1

u/taostudent2019 Sep 04 '20

Can you recommend a system or software that handles this? Or a source for a How-To?

2

u/esunabici Sep 04 '20

My preference is Salt Stack. I think many prefer Ansible. Chef and Puppet are other popular options.

It may be nice to pick one written in a programming language you know, but it's more important to pick one with a large community.

1

u/taostudent2019 Sep 04 '20

I'm currently trying to keep everything on Python.

To be honest, I realized a long time ago. I don't pick the language for any good reason. I end up working with some idiot who has bad habits and slowly end up hating that language along with the idiot.

I've been lucky so far with Python. But I'm also run out of languages. :D

2

u/esunabici Sep 04 '20

That's convenient. Salt Stack and Ansible are both written in Python. It's rarely necessary to got that deep, but it can be convenient to be able to. The configuration is written in YAML for both.

3

u/deong Sep 04 '20 edited Sep 04 '20

This type of thing is why I still install Linux systems with separate partitions for /, /home, and /usr/local at a minimum. My files go in /home. Stuff I've installed outside the package manager goes in /usr/local. Obviously your permissions on those will be messed up too, but that's generally easier to deal with even if you don't have backups.

Reinstalling is just a matter of letting the installer put everything back in /. Bonus points if you have a regular backup of all your installed packages so that you can reinstall them all with one line later.

1

u/taostudent2019 Sep 04 '20

My laptop is a freaking mess. But my servers are getting nicer.

The way I have it set up is an application or an environment is a separate user. And the home is just for logging in and that type of basic functionality.

I'm actually having trouble finding a good back up program. I was hoping there was something super simple that would back up onto the same machine. And I could just mirror the drive on top of that. Then I would have Git, database backups, mirrored drives, and a nice little back up right on the system of the whole hot mess.

But if it is a mirrored drive and a fresh install, you have to pass new keys and get it talking to all the other machines again which always takes some time.

2

u/lumixter Sep 04 '20

Quick protip for the future, if you're ever wanting to backup your permissions somewhere that you're doing a recursive change, you can do it pretty easily with getfacl.

# getfacl -R --absolute-names /path/to/directory > /path/to/faclbackup

and to restore them you can just do:

# setfacl --restore /path/to/faclbackup

0

u/[deleted] Sep 04 '20

[deleted]

2

u/ZaoLahma Sep 04 '20

I've done things like that so many times that I'm considering revoking my sudo permissions on my own damn laptop.

96

u/SlinkyAvenger Sep 04 '20

technically didn't break anything

setting execute on everything for everyone breaks security pretty seriously though... so there's that.

29

u/djamp42 Sep 04 '20

Security sure, functional wise I think it would be fine.

26

u/Nibodhika Sep 04 '20

Not necessarily, some files required exact permissions to work, e.g. swapfiles, so I wouldn't be surprised if some things refused to work if their settings were executable or something like that.

That being said, I don't think there are many checks like this, so it is entirely possible that the system keeps working. And now I'm curious about it

2

u/roachh2 Sep 04 '20

I've got like 50 spare arch VMs so I could fuck around with it perhaps

16

u/[deleted] Sep 04 '20

[removed] — view removed comment

2

u/ThellraAK Sep 04 '20

Playing with sshCA I learned way more then I wanted to about ssh configs in the last few days, AFAIK, it cares about readability, not whether or not its an executable.

4

u/[deleted] Sep 04 '20

[removed] — view removed comment

2

u/ThellraAK Sep 04 '20

I'll mess around with it tonight, but all the warnings and refusals just say not group or world readable, a few of them say not world or group writable because you can do dangerous things in there, but none mention no execute.

2

u/Parker_Hemphill Sep 04 '20

Execute is still needed for directories. Try the following to see what I mean:

cd /dev/shm
mkdir test_directory
cd test_directory && cd ..
chmod a-x test_directory
 #Removing execute for everyone on test
cd test_directory && cd ..

You'll notice you get a permission denied the second time. Execute has a different use for directories than it does for files.

3

u/ThellraAK Sep 05 '20

When my ~/.ssh/authorized_keys is

-rwx--x--x

It still worked fine

/etc/ssh# chmod +x *
root@Copy-of-VM-9002:/etc/ssh# ls -la
total 600
drwxr-xr-x  4 root root   4096 Sep  4 20:54 .
drwxr-xr-x 77 root root   4096 Sep  4 20:52 ..
-rwxr-xr-x  1 root root 535195 May 28 23:37 moduli
-rwxr-xr-x  1 root root   1603 May 28 23:37 ssh_config
drwxr-xr-x  2 root root   4096 May 28 23:37 ssh_config.d
-rwx--x--x  1 root root   1393 Sep  4 20:51 ssh_host_dsa_key
-rwxr-xr-x  1 root root    999 Sep  4 20:54 ssh_host_dsa_key-cert.pub
-rwxr-xr-x  1 root root    610 Sep  4 20:51 ssh_host_dsa_key.pub
-rwx--x--x  1 root root    513 Sep  4 20:51 ssh_host_ecdsa_key
-rwxr-xr-x  1 root root    571 Sep  4 20:54 ssh_host_ecdsa_key-cert.pub
-rwxr-xr-x  1 root root    182 Sep  4 20:51 ssh_host_ecdsa_key.pub
-rwx--x--x  1 root root    411 Sep  4 20:51 ssh_host_ed25519_key
-rwxr-xr-x  1 root root    495 Sep  4 20:54 ssh_host_ed25519_key-cert.pub
-rwxr-xr-x  1 root root    102 Sep  4 20:51 ssh_host_ed25519_key.pub
-rwx--x--x  1 root root   2610 Sep  4 20:51 ssh_host_rsa_key
-rwxr-xr-x  1 root root    963 Sep  4 20:54 ssh_host_rsa_key-cert.pub
-rwxr-xr-x  1 root root    574 Sep  4 20:51 ssh_host_rsa_key.pub
 -rwxr-xr-x  1 root root    342 Aug 31 21:46 ssh_import_id
-rwxr-xr-x  1 root root   3446 Sep  4 20:54 sshd_config
drwxr-xr-x  2 root root   4096 May 28 23:37 sshd_config.d

Does cause sshd to lose it's shit

Sep 04 21:03:13 Copy-of-VM-9002 sshd[1158]:       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    @@@@@@@@@@@@@@@@@@@
Sep 04 21:03:13 Copy-of-VM-9002 sshd[1158]: @         WARNING: UNPROTECTED  PRIVATE KEY FILE!          @
Sep 04 21:03:13 Copy-of-VM-9002 sshd[1158]:     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@@@@@
ep 04 21:03:13 Copy-of-VM-9002 sshd[1158]: Permissions 0711 for '/etc/ssh      ssh_host_rsa_key' are too open.
Sep 04 21:03:13 Copy-of-VM-9002 sshd[1158]: It is required that your private key files      are NOT accessible by others.
 Sep 04 21:03:13 Copy-of-VM-9002 sshd[1158]: This private key will be ignored.
 Sep 04 21:03:13 Copy-of-VM-9002 sshd[1158]: 
Sep 04 21:03:13 Copy-of-VM-9002 sshd[1158]: sshd: no hostkeys available -- exiting.
  Sep 04 21:03:13 Copy-of-VM-9002 systemd[1]: ssh.service: Control process exited, code=exited, status=1/FAILURE

That's gotta be a bug, 711 is not 'open' config man's say 'group or world readable' not must be *00

→ More replies (0)

2

u/12_nick_12 Sep 04 '20

I think that depends on distro. I don’t think Debian cares, but CentOS does.

5

u/morgan_greywolf Sep 04 '20

Probably. There are a few things that require very specific permissions and will refuse to work if those permissions are exceeded at all, but you won't encounter those on many systems.

1

u/SlinkyAvenger Sep 04 '20

SSH is something that's very common that is like that

3

u/ThellraAK Sep 04 '20

Those can be whatever, as long as they aren't group or world readable.

1

u/spoodie Sep 04 '20

sudo may stop working if the config files have unexpected permissions.

11

u/Sol33t303 Sep 04 '20

Wonder if you could maybe get a copy of all of a distros files, then copy the permissions from them. That would probably fix the majority of them, after that i'm sure that you could hunt down the remaining executables with the find command.

25

u/xxpw Sep 04 '20

You would solve 99% in few seconds. But fixing the last %... would take you days.

3

u/Sol33t303 Sep 04 '20

I know find can execute a command on each file it finds, so you can set it to find all executables, then unmark it as executable, and ignore the bin directories.

I think that would work, there are VERY few executables normally outside of the bin directories AFAIK. So that could maybe work. Then if a couple files that were meant to be executable but were unmarked executable then that would cause an issue you could probably track back fairly easily to the not executable file. Wouldn't be fast but it'd work.

3

u/xxpw Sep 04 '20

Very few is infinitely more than none.

And only one of those (shouldn’t be) executables can be a MD weapon security wise (it’s actually one of the first vectors you learn)

Your system might look ok and be perfectly workable... but it’s a Swiss cheese you really shouldn’t trust.

There is no definitive practice on the topic (because UNIX is an oooold man with an old heritage)... so yeah find -exec helps, but you’ll need to go much further.

Just roll back to a safe backup.

Edit: carriage return is broken on reddit.

3

u/furrowed_rhino Sep 04 '20

in proper environment we use AIDE to create a database of all files (that includes what permission they have, and their md5 as well) which allows us to walk back situations like these.

without aide running on the machine I would do this:

reinstall on a different machine the same distro and make it as similar to the proper state of this machine as possible (programs installed, configs and so forth).

script a bash thing with finds that saves the name of each file and it's permission

script a bash thing that takes that list of files and permissions from the other machine and apply it to this one.

print a list of files that are present on this machine and not the new one, do educated guesses on what permission they should have.

in fact since he only added an +x that wouldn't be so bad to walk back.

0

u/[deleted] Sep 04 '20

[removed] — view removed comment

6

u/AquaL1te Sep 04 '20

You can... If you have a reference system. No way you really fixed it..