Why logging in as root is a bad idea

andres101

Expert Member
Joined
May 14, 2004
Messages
2,124
Reaction score
2
Location
/\/¯¯¯¯¯\/\
I've been a Linux user for years and I never log in to a window manager using the root account.

However, when I ssh into a machine, I normally want to do admin that requires root privileges, so I normally log in as my user and sudo su root, so that I don't have to sudo... the whole time.

Last night I ssh'd into my HTPC and long story short, I deleted everything in /etc older than 30 days... which is basically everything! Even my passwd file is gone! Backups? What backups?

Luckily I'm running Gentoo so as soon as I get my toolchain back up, I should be able to get most of the files replaced. Currently cross-compiling gcc and glibc...

Now that I've had my first big root oops, I will never log in as root again.
 
Last edited:
why is it that people (including myself) only learn the hard way?
 
ROFL! Ubuntu has at least got me into the habit of putting sudo before everything that needs it.

Gotta love that XKCD cartoon...

sandwich.png
 
Last edited:
It's become routine for me to type sudo :D
root is just too dangerous for me at times :o
 
I spend most of my day logged in as root on clients' servers. I guess once you get used to just how much you can destroy, you are a lot more careful. Fortunately I haven' had an accident... yet.

One of the other sysadmins I used to work with, however, once had the following misfortune:

"Hmm... I need to delete a folder in /usr/local/bin..."
$rm -rf /*hits enter key by mistake as it is right next to "/"*
"OH SHI-"

I learned two things from this:

1. Always double check anything that might be even slightly dangerous before hitting enter (especially something beginning with rm -rf)
2. NEVER, EVER, EVER use a keyboard with the enter key next to the / key. EVER.
 
Also helps to use
Code:
ls
on the expression you want to
Code:
rm -rf
 
Professionally I do agree... and though I use root on a close to permanent basis, I obviously wouldn't recommend it. But for the record, I've never broken or formatted or done anything destructive to my machine in all the years I've been running Linux.
 
Where I work I spend all day doing sysadmin and troubleshooting on Linux servers (60k or so, growing daily), all of which requires root privileges. Typing sudo all the time is just too much of a hassle. Sure, at home where do the occasional bit that needs root privs, sudo is just fine. If I was working somewhere where I only logged into occasionaly, it would have been a different story. But for my job it's real root.

Two habits that help:

1. Modify your shell to execute 'pwd' - that way you always have a reminder where on the filesystem you are.

2. Type full paths when deleting.
 
I tested the command on etc:
find /etc -type f -ctime +30 | xargs ls

then copied and pasted it into my script file and forgot to replace /etc with $1, so I ended up with:
find /etc -type f -ctime +30 | THIS WILL MESS UP YOUR SYSTEM!xargs rm

Most of my critical system components are working again. I just accidentally rebooted the pc and it actually booted.
 
Top
Sign up to the MyBroadband newsletter
X