Aliases for root

Hi folks. I often sudo su into root to get some things done. I can’t use su directly, as it doesn’t work in 8.6 but that’s another topic.

I would like to have some aliases set up for root, but there is no home for this user, as predicted as /home/root. How can I add aliases to the root user? There doesn’t seem to be any .bash_profile file anywhere.

First, why ‘sudo su’? That runs the command ‘su’ as root, and the point of ‘su’ is to become root. Seems redundant. How about sudo -i ?

Second, the ‘su’ definitely works on EL8. It does work on EL9 too, but lets leave that for the other topic.

If you want to run specific commands via aliases, you could have those aliases on your regular account.
For example: alias sc2='sudo systemctl'

Third, “as predicted as /home/root”? How did you “predict” that?
The root definitely should have a home directory, but it is not under /home.
See output of getent passwd root

su doesn’t work.

[2022_Jul_28 15:22:50 user1@server_f ~] su
su: cannot set groups: Operation not permitted

I have plenty of aliases on my regular account. I’ve used these aliases for over a decade. I’d like to bring them into the root user, as I have done on many other operating systems. It doesn’t seem like I can on AL 8.6.

How did I predict that? With other operating systems that have just that. It seems .bash_profile is in /root. What I was looking for.

of course su works, although you should use su -

sudo su is pretty silly, but usually its used to lock down which accounts can us su - i.e. nobody can use su directly, only these accounts listed in sudoers can run it. i prefer to only allow users in the wheel group access to su and disable sudo entirely.

that error is usually as some jobsworth from security has removed the setuid bit on the su binary :smiley:

not sure what unix you’re used to, but i’ve never seen root’s $HOME set as /home/root on linux, solaris, hpux, freebsd, openbsd, netbsd, aix, tru64, macos… it’s always either /root or /

setting aliases for root is almost as bad an idea as running x11 as root, but you can set them in ~/.bashrc or ~/.bash_aliases, assuming root is using bash

su works on 9. su is not su -. Also sudo su - <username> instructed by PostgreSQL, is where I got that from.

The aliases have been set. Why is it a bad idea? Why would having aliases not be useful for root? It’s always been a great idea for me. I don’t see why not. I think closing out root is a bad idea. But to each their own.