# accidentally moved and fixed /bin/ directory, but now can't su

I accidentally moved my /bin directory to /usr/bin/bin, anyway, I managed to move it back to its place with

# /usr/bin/bin/mkdir /bin
# /usr/bin/bin/mv /usr/bin/bin /


and then I was able to login as root, but I wasn't able to su from my user, it gave me an authentication error. I ran chmod +s /bin/su and chmod u+s /bin/su as root, and it fixed it.

another thing I noticed is that I can't ping either; it gives me this error:

\$ ping 192.168.1.1
ping: icmp open socket: Operation not permitted


and this is my ping file:

-rwxr-xr-x 1 root root 44K Jun 30 20:38 /bin/ping


I guess I messed up all the permissions and SGID on my /bin folder. Is there any way to fix this? (other than formatting)

Just for the record, I'm using a 64 bit Debian 8.

• How did you actually break /bin? Just moving it wouldn't have destroyed setuid features on files it contained. Without this information it's going to be very tricky to help you restore it again. – roaima Jul 1 '15 at 20:38
• I don't know!! I just accidentally moved it to /usr/bin, and then fixed it by moving it back... i am as confused as you :S is there any way to restore the permissions the way it was? it is an almost clean linux install, since I installed it yesterday. – Bengalaa Jul 1 '15 at 21:19
• At least, did you use mv, cp, tar…?↵(the missing return) The ping problem has no relation with your /bin war maneuvers: its mode, owner & group are correct. – dan Jul 1 '15 at 21:36
• I just used mv, as root... I wanted to install a self-made script, so I used cp my-script /bin/, it didn't work, so I attempted to move it to /usr/bin, but I accidentally my whole /bin/ into /usr/bin/, then I realised I forgot to add execute privileges to my script... and I feel like a moron now – Bengalaa Jul 1 '15 at 22:17

I would debootstrap a base system to another directory.

debootstrap --variant=minbase --arch=amd64 jessie /tmp/bootstrap http://ftp.us.debian.org/debian/


Then copy all files from /tmp/bootstrap/bin to /bin keeping the permissions.

cp -a /tmp/bootstrap/bin/* /bin/


Now many (and the basic ones) of your files in /bin should be ok and you should be able to see which were not touched using the timestamp (old files can have wrong permissions).

For the rest you can use

apt-get install --reinstall PACKAGE


to set the permissions back.

You can find the package to a file with

dpkg -S /path/to/file


This is even scriptable...

Good luck!

• I was about to suggest a solution like this one but yours is easier (particularly as it's just /bin to be fixed). – mjturner Jul 1 '15 at 21:30
• Thats nice. Didn't know that! And I am not sure, whether mine really is easier. Yours is just one script. And you could add a check, so only files in /bin are reseted. – Jodka Lemon Jul 1 '15 at 21:32
• that's a very elegant answer!! it worked like a charm... i ran a cp -r -a /tmp/bootstrap/bin/* /bin/ just to be sure... thanks a lot! – Bengalaa Jul 1 '15 at 22:11