Setting an Alias as root

Posted on 2005-05-12
Medium Priority
Last Modified: 2013-12-27
I wanted to know how to set an alias as root
I can set an alias while logged in as root
alias psm "/usr/ucb/ps auxgw | more"
but this is removed once I log out.
how would I set a permanant alias?

Question by:Troder
  • 2
  • 2
LVL 34

Accepted Solution

PsiCop earned 500 total points
ID: 13988025
When you login as root, execute your fave shell (bash, tcsh, zsh, whatever). Have the appropriate configuration (.profile, .cshrc, whatever) file in root's home directory and put the configuration statements you want in there (for example, command aliases).

DO NOT change root's shell!!

Leave it as sh. Instead, run whatever shell you prefer, after logging in as root.

Expert Comment

ID: 13988027

Create a file calle /.profile and put the 'alias ...' line in the file.

When a user logs in his .profile is run.  This can also be used to add directories to the PATH, MANPATH etc.

Hope this helps,

Regards, Nisus
LVL 34

Expert Comment

ID: 13988037
Optimally, you should never log directly in as root. Instead, log in as yourself, and either use sudo to escalate privledge for specific tasks, or use su to gain root privs. Allowing root login from anywhere but the console, especially if you're not using SSH, is a Bad Idea (tm).

Expert Comment

ID: 13988107
PsiCop is perfectly correct.  In fact I would prefer to use ssh rather than telnet.  You can setup trusting so it is a trivial matter to wander around all your servers, and everything is encrypted.

LVL 38

Expert Comment

ID: 13992439
If you did not setup the box, have a look at the /etc/passwd to find out where's the root's
home dir, default is /, but some sys adm (including me) put the root's home dir in a place
other then /. then modify (or create) the .profile file under root's home dir and put your
alias in the file, you can add other ENV settings eg:
PATH,  MANPATH, LD_LIBRARY_PATH .... etc in the same file.

For security reason, turn off telnet and ftp in your system (plain text password), use ssh
instead. at least don't allow root telnet/ftp from outside to the box.

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question