LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-08-2009, 04:00 PM   #1
surya_prakash
LQ Newbie
 
Registered: Oct 2008
Location: Hyderabad
Posts: 26

Rep: Reputation: 15
Aliases got lost


Hi,

I logged into my linux system with a limited user and entered the root using " su " command in the terminal. Then i added some aliases from the root login.then i logged out from root.and again i acquired the root login using "su " command .when i type the alias command it is not showing the previously added aliases.
 
Old 05-08-2009, 04:04 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
When you add an alias it is in the current shell. To add it automatically next time you become the user you need to add it to that user's startup files ($HOME/.bashrc and/or $HOME/.bashprofile assuming you're using bash shell).

Also note that when you do "su root" (or just "su" since root is default user) you are NOT invoking the environment of the root user. You must type "su - root" or "su -" to invoke that environment. Otherwise it is using the environment it had before the switch to root.
 
Old 05-08-2009, 04:05 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
Where did you put your aliases definition? If you simply write them on the command line, they are local to the current shell and are lost when you terminate the session. If you put them in a file which is sourced every time you login, as $HOME/.bashrc, you retrieve your aliases (or functions).
 
Old 05-08-2009, 04:09 PM   #4
surya_prakash
LQ Newbie
 
Registered: Oct 2008
Location: Hyderabad
Posts: 26

Original Poster
Rep: Reputation: 15
thanks

yes,if i add aliases by logging as "su - root". I only see aliases when login as "su - root".If i login as "su " i could not see any .


why
 
Old 05-08-2009, 04:11 PM   #5
surya_prakash
LQ Newbie
 
Registered: Oct 2008
Location: Hyderabad
Posts: 26

Original Poster
Rep: Reputation: 15
there is nothing like .bashrc file in HOME. I could only find .bash_history
 
Old 05-08-2009, 04:20 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
Quote:
Originally Posted by surya_prakash View Post
thanks

yes,if i add aliases by logging as "su - root". I only see aliases when login as "su - root".If i login as "su " i could not see any .


why
As jlightner already said, when you switch to root using su without the hyphen, you keep the environment of the current user. When you use su - you switch to root starting a login session. In this way all the files are sourced at login (.bash_profile, .bashrc and so on) and the root's environment is set up.

Quote:
Originally Posted by surya_prakash View Post
there is nothing like .bashrc file in HOME. I could only find .bash_history
.bashrc is not mandatory, but you can always create it if necessary. If it misses, most likely you don't use /bin/bash as login shell. Anyway, you didn't replay to my previous question: where did you put the aliases? If not in the missing .bashrc, to which file have you added them?

Last edited by colucix; 05-08-2009 at 04:22 PM.
 
Old 05-08-2009, 04:23 PM   #7
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
$HOME not just "HOME".

$HOME is the home directory of the user. This could be something like:
/
/root
/home/root
/billybob

It is whatever was defined as the user's home directory in /etc/passwd. You can find out what it is by doing the "su -" then typing "echo $HOME".

If there is no .bashrc in root's $HOME you can create it. Of course this also assumes the shell for root is bash. If it were zsh or ksh you might need a different file. The last thing for root user in /etc/passwd is the shell it uses.
 
Old 05-08-2009, 04:37 PM   #8
surya_prakash
LQ Newbie
 
Registered: Oct 2008
Location: Hyderabad
Posts: 26

Original Poster
Rep: Reputation: 15
yes i create .bashrc file in $HOME and added the aliases. I could able to find the alias even if login into root as "su ".

Thanks


And one more doubt is

Currently i logged into a user prakash the terminal prompt is showing as prakash@prakash.domain.name]$

if i logged in as root previosly it showed like

root@prakash.domain.name]#

But now if i logged in as root it is showing like

bash-3.1#

Why is it happening so?
 
Old 05-10-2009, 10:34 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,419

Rep: Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785
That's the 'normal' basic root prompt (especially the '#') to show you are root.
You can customise it by looking at the contents of /etc/profile, /etc/bashrc, looking for the word 'PROMPT' and editing the user's .bashrc as needed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
aliases Lost When Using screen MQMan Slackware 10 04-18-2011 06:25 PM
aliases issue using /etc/aliases lensem Linux - Software 3 04-14-2009 01:48 PM
wrap lines at 80 for long aliases in .aliases.csh jhwilliams Linux - Software 0 07-26-2007 08:49 AM
Bind have lost some zone in named.conf & lost db file achilles Linux - Enterprise 0 04-19-2007 07:22 AM
sendmail and NIS databases (aliases, mail.aliases) - what kind of databases? cotton213 Linux - Software 0 03-14-2006 06:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration