4 ms·
You know what? Sometimes, it's fine. You should not share a root account with other users. This advice comes from a time where you'd have the "root password" an
by IgorPartola 13y ago
You know what? Sometimes, it's fine. You should not share a root account with other users. This advice comes from a time where you'd have the "root password" and log into remote servers that way. Then, when someone leaves your organization, you'd hopefully change the root password to make sure they person that left no longer has access.
However, there are some concrete cases where logging in as root is just fine:
- Making a database backup remotely. You have to give the backup user enough privileges to initiate a database dump, stop the database process, grab the backup, rotate the backups, start the database process up again. You can go through the giant pain of setting up the permissions just so, or you can put a separate SSH public key into /root/.ssh/authorized_keys and just let root do all of this.
- Initial VM setup. If you are automating something like provisioning EC2 instances, sure go ahead and set up individual users, but it's a lot easier to first connect as root using your own keypair.
- A remote monitor that logs into a single purpose VM to restart a process. Same as the backups example, but more broad. Once again, you could set it up using specific users, but the system would be more brittle.
- Lots of other cases where root is really what you want and doing sudo won't work because the session is not interactive.
I figure it this way: if I compromised a local account on a server, I'd just add `alias sudo=~/.bin/my-evil-sudo-that-emails-your-password` to your .bashrc. That way I'd get root without any local exploits in the kernel, etc. Basically, adding extra protection around the root account does nothing if you are a sudoer.
Some steps you can take to actually increase your security instead of following the advice that is so misunderstood:
- Set the root password to a long random string, then lose the string. `su` should never be used by anyone but root.
- Disable password logins. Period. Do this now, and do it everywhere.
- Disable password-based sudo. Use pam_ssh_agent_auth [1] to escalate privileges and ssh-agent to forward your key through your ssh session. I am not sure why this isn't the default, but it really ought to be.
- Make sure your local key is encrypted with a strong passphrase. Once again, use ssh-agent to not have to enter the password every single time.
- Set up a VPN to access your servers and only allow ssh from the VPN.
- For the truly paranoid, set up two-factor auth over SSH. This is easy to do with Google Authenticator (it's just a random number with the seed being shared and secret and the number being generated every 30 seconds), or using SMS which is just slightly more complex/costly.
[1] http://pamsshagentauth.sourceforge.net/ http://pamsshagentauth.sourceforge.net/
- jamiesonbecker 13y agoWith regards to initial VM's, I agree sometimes -- sometimes you just gotta get it done. But the others (db backup, remote monitor, etc) should use separate acct plus sudo. use userify or cloudadmins or something home-grown to manage those system accts, don't one-off and don't leave root on a net-connected machine for more than a few minutes. (also goes for all other generic accounts like ec2-user, ubuntu, etc). asap, passwd -l root; sed -i "s/PermitRootLogin *yes/PermitRootLogin no/" /etc/ssh/sshd_config
- IgorPartola 13y agoI think the advantage of using a separate but privileged account is not as great as you think. If an attacker compromises that privileged account, chances are they will own root anyways. Why bother with the complexity then?
- dec0dedab0de 13y agobecause they would have to guess the username too. everyone already knows root exists.
- stormbrew 13y agoIf knowing an account exists is like getting to the moon, logging into it if it requires a private key is like getting to Andromeda. I mean, I tend to turn root access off, but let's not oversell what kind of security it gets you. There is effectively zero security difference between a non-root account + passwordless sudo and a root account if they both require a key to log in.
- IgorPartola 13y agoI think jamiesonbecker was implying that this new user would have sudo restricted to just doing the tasks required for its individual purpose, not completely open sudo. I disagree with their point, but yeah, that would have nothing to do with guessing the account name.