Solved Where to define an alias for root

I apologize for the simplicity of this question, the answer to which is probably going to be as simple.

I made an entry in /root/.shrc for an alias like la='ls -alh'. Once I source this file, it does work. However, I have to source this file every time I su to root via ssh. I need this alias to be recognized in that scenario without having to source the /root/.shrc file. What am I missing?

Yes, I verified that my shell is sh:
Code:
# echo $SHELL
/bin/sh
 
In addition to this answer.
su(1)
Code:
     -l      Simulate a full login.  The environment is discarded except for
             HOME, SHELL, PATH, TERM, and USER.  HOME and SHELL are modified
             as above.  USER is set to the target login.  PATH is set to
             “/bin:/usr/bin”.  TERM is imported from your current environment.
             Environment variables may be set or overridden from the login
             class capabilities database according to the class of the target
             login.  The invoked shell is the target login's, and su will
             change directory to the target login's home directory.  Resource
             limits and session priority are modified to that for the target
             account's login class.

     -       (no letter) The same as -l.
sudo(8)
Code:
     -i, --login
             Run the shell specified by the target user's password database
             entry as a login shell.  This means that login-specific resource
             files such as .profile, .bash_profile, or .login will be read by
             the shell.  If a command is specified, it is passed to the shell
             as a simple command using the -c option.  The command and any
             args are concatenated, separated by spaces, after escaping each
             character (including white space) with a backslash (‘\’) except
             for alphanumerics, underscores, hyphens, and dollar signs.  If no
             command is specified, an interactive shell is executed.  sudo
             attempts to change to that user's home directory before running
             the shell.  The command is run with an environment similar to the
             one a user would receive at log in.  Most shells behave
             differently when a command is specified as compared to an
             interactive session; consult the shell's manual for details.  The
             Command environment section in the sudoers(5) manual documents
             how the -i option affects the environment in which a command is
             run when the sudoers policy is in use.
 
Just for future reference, one can also define the alias in the user's .shrc file, who connects to the host via ssh. They can then elevate privilages with
su instead of su - if typing two more characters is a big deal 😄.
 
Back
Top