LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   setting env variables. (https://www.linuxquestions.org/questions/programming-9/setting-env-variables-714855/)

mannclay 03-27-2009 08:59 AM

setting env variables.
 
When I open a terminal, I get get bash. When I use su and go to root I get sh.

How do I change what shell is used in root?

Thanks...

theNbomr 03-27-2009 09:45 AM

It is set in /etc/passwd.
--- rod.

mannclay 03-27-2009 09:54 AM

I found it! Thanks.
now, how do I change it to bash? I don't think 'nano passwd' will do anything.
Is there any reason why it is set to sh?

theNbomr 03-27-2009 10:00 AM

As root, you can edit it to whatever you choose.
--- rod.

mannclay 03-27-2009 10:04 AM

thanks.
By the way, how can I permanently keep the -G option for ls??

Hko 03-27-2009 10:07 AM

Quote:

Originally Posted by mannclay (Post 3489635)
now, how do I change it to bash? I don't think 'nano passwd' will do anything.

Actually, editing /etc/passwd with nano (while being root of course) and change /bin/sh to /bin/bash would do the trick. You do need to re-login though to feel the effect. Also, take good care editing /etc/passwd. If you make a mistake, you may well lock yourself out, i.e. not be able to log in anymore.

A cleaner way is to run the "chsh" command. It will ask you for the new shell. Press enter and your dropped in your new shell right away. And there no risk of making dangerous mistakes. Also, non-root users can use "chsh" to change their own shell.

theNbomr 03-27-2009 10:28 AM

You could use an alias (assumes bash shell)
Code:

alias ls='ls -G'
Put this in a bash startup script, such as your local .bashrc and subsequent logins will acquire that alias. Without logging in, such as immediately after editing the file:
Code:

source ~/.bashrc
This will pull in whatever settings are effected in the startup script.
--- rod.

Telemachos 03-27-2009 10:39 AM

I think it's far safer to use the chsh program to change your shell, rather than editing /etc/passwd directly. (Just become root and then enter chsh.)

I would go further and say you should never edit that file directly if you can avoid it. (Maybe I'm being overly cautious.)

Apologies - Hko got there first. I should have read more slowly.

theNbomr 03-27-2009 10:55 AM

Quote:

Originally Posted by Telemachos (Post 3489682)
I think it's far safer to use the chsh program to change your shell, rather than editing /etc/passwd directly. (Just become root and then enter chsh.)

I would go further and say you should never edit that file directly if you can avoid it. (Maybe I'm being overly cautious.)

Not necessarily disagreeing, but what makes chsh fundamentally safer? As I see it, either tool is simply editing a system file. I guess you could ague that it is more convenient...
--- rod.

Hko 03-27-2009 11:35 AM

Quote:

Originally Posted by theNbomr (Post 3489704)
Not necessarily disagreeing, but what makes chsh fundamentally safer? As I see it, either tool is simply editing a system file. I guess you could ague that it is more convenient...

The fields in /etc/passwd are seperated by colons. Imagine you accidentally delete or overwrite one of those. Or you make a typo in the shell-field (eg. "bash" instead of "/bin/bash).

"chsh" checks if your entry is valid as shell and thus protects you from all typos (eg. /bin/bosh).

Telemachos 03-27-2009 07:51 PM

Quote:

Originally Posted by theNbomr (Post 3489704)
Not necessarily disagreeing, but what makes chsh fundamentally safer? As I see it, either tool is simply editing a system file.

I should have made myself clearer, but as Hko said (again, he's ahead of me), the advantage to chsh is that it doesn't allow the changes to be saved unless they are sane. (The danger of an error is significant. If you mess up badly enough, you lock yourself out of the relevant account.) Another example is to use visudo to work on your /etc/sudoers file, again rather than editing it directly.

Now I'm curious: does anyone know of other similar examples?

Hko 03-27-2009 08:14 PM

Quote:

Originally Posted by Telemachos (Post 3490134)
Now I'm curious: does anyone know of other similar examples?

I can only think of one at the moment: crontab -e
Though this does not write in /etc but somewhere in /var/spool/...

And of course using the command passwd instead of typing your root password into /etc/passwd with an editor. :-)


All times are GMT -5. The time now is 08:50 AM.