LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to get bash prompt right after logging into a server? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-get-bash-prompt-right-after-logging-into-a-server-865495/)

chekhov_neo 02-28-2011 10:34 AM

How to get bash prompt right after logging into a server?
 
Hi,

Everytime I log into the linux server at my workplace (I use putty), I don't get the bash prompt right away. I need to execute the command 'bash' to get it. Anyway to make this automatic?

e.g.

Code:


host:1>
host:1> bash
user@host:~$

Thanks,
Arun

TB0ne 02-28-2011 10:59 AM

Quote:

Originally Posted by chekhov_neo (Post 4274013)
Hi,
Everytime I log into the linux server at my workplace (I use putty), I don't get the bash prompt right away. I need to execute the command 'bash' to get it. Anyway to make this automatic?

e.g.
Code:

host:1>
host:1> bash
user@host:~$


Have the administrator change your shell to be bash. You're getting a prompt, but it's for a different shell.

AlucardZero 02-28-2011 10:59 AM

chsh -s bash

chekhov_neo 02-28-2011 11:27 AM

more trouble
 
Quote:

Originally Posted by AlucardZero (Post 4274029)
chsh -s bash

Well sir, I'm in a quandary now. I tried changing the shell using chsh -s bash when I was logged in as 'user' and got the following output:

Code:

user@host:~$ chsh -s bash
Password:
bash is an invalid shell.
user@host:~$

I should have stopped with that but I logged in as root and executed the same command. Now when I try to login as root I get the following error:

Code:

host:21> su root
Password:
No shell
host:22>

I don't know why it is saying bash is an invalid shell. The following are the contents of /etc/shells

Code:

user@host:~$ cat /etc/shells
# /etc/shells: valid login shells
/bin/ash
/bin/bash
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
/usr/bin/rc
/usr/bin/tcsh
/bin/tcsh
/usr/bin/zsh
/bin/sash
/bin/zsh
/usr/bin/esh
/bin/rbash
/bin/dash
/usr/bin/screen
user@host:~$

Then I tried the following in vain:

Code:

user@host:~$ chsh root
You may not change the shell for root.
user@host:~$

I'm unable to login to the server as root. Please help...!

arizonagroovejet 02-28-2011 11:30 AM

Quote:

Originally Posted by chekhov_neo (Post 4274076)
I don't know why it is saying bash is an invalid shell. The following are the contents of /etc/shells


And that list of shells doesn't include bash. It does include /bin/bash though...

chekhov_neo 02-28-2011 11:32 AM

Quote:

Originally Posted by arizonagroovejet (Post 4274080)
And that list of shells doesn't include bash. It does include /bin/bash though...

Aren't they both the same thing?

chekhov_neo 02-28-2011 12:07 PM

got root access!
 
Ok, after doing some googling I resolved my current problem(phew!) by doing the following:

Code:

host:32> env | grep SHELL
SHELL=/bin/csh
host:32> su -c 'chsh -s /bin/csh root'
Password:
host:33>
host:33> su root
Password:
host:/bin#
host:/bin#

I'm able to login as root. Now my thought is this, "Don't screw up any more. Let your administrator handle it" :)

arizonagroovejet 02-28-2011 01:00 PM

Quote:

Originally Posted by chekhov_neo (Post 4274082)
Aren't they both the same thing?

OK, I'll spell it out: Change your shell to /bin/bash, not bash.

chekhov_neo 02-28-2011 01:22 PM

Ok, I tried with "/bin/bash/" and I'm getting this now:

Code:

user@host:~$ chsh -s /bin/bash
Password:
chsh: user not found in /etc/passwd
user@host:~$

Should I add my username in /etc/passwd file?

And one quick question. Why didn't "chsh -s bash" work when the directory "/bin" is present in my PATH environment variable?

devUnix 02-28-2011 02:43 PM

/etc/shells is a file that contains shells which are generally found in /bin as shown here:

Command: 1

Code:

-bash-2.05b# ls -l /etc/shells
-rw-r--r--  1 root root 80 Jul 22  2004 /etc/shells

Command: 2

Code:

-bash-2.05b# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/bash2
/bin/ash
/bin/bsh
/bin/tcsh
/bin/csh
-bash-2.05b#

This will also do the same thing as above:

Code:

-bash-2.05b# chsh --list-shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/bash2
/bin/ash
/bin/bsh
/bin/tcsh
/bin/csh
-bash-2.05b#

Command: 4

Code:

-bash-2.05b# for Shell in `cat /etc/shells`; do ls -l $Shell; done
lrwxrwxrwx  1 root root 4 Jul 27  2004 /bin/sh -> bash
-rwxr-xr-x  1 root root 593304 Mar 11  2004 /bin/bash
-rwxr-xr-x  1 root root 4636 May  4  2004 /sbin/nologin
lrwxrwxrwx  1 root root 4 Jul 27  2004 /bin/bash2 -> bash
-rwxr-xr-x  1 root root 98388 Feb 16  2004 /bin/ash
lrwxrwxrwx  1 root root 3 Jul 27  2004 /bin/bsh -> ash
-rwxr-xr-x  1 root root 319520 Feb 17  2004 /bin/tcsh
lrwxrwxrwx  1 root root 4 Jul 27  2004 /bin/csh -> tcsh
-bash-2.05b#

We need to specify the complete path for the named shell even if the /bin directory is included in the $PATH variable:

Code:

-bash-2.05b# chsh -s sh
Changing shell for root.
chsh: shell must be a full path name.
-bash-2.05b#

But to change your Shell temporarily, you can simply type its name and hit the enter key:

Code:

-bash-2.05b# sh
sh-2.05b#

Without changing your login shell permanently either by executing the chsh -s command or by asking your system admin to make change sin the /etc/passwd file, you can simply put this line of code in your csh (if that is the default shell) or bash (if this is the default shell) profile file. For example, my default login shell is bash. But to get sh every time I login to the server, I can do the following:

Code:

sh-2.05b# cat .bash_profile
PATH=$PATH:$HOME/bin:.
export PATH
echo "Welcome, Dev! Have happy working hours!"
/bin/sh
sh-2.05b#

Even if my default login shell is /bin/bash:

Code:

sh-2.05b# grep ^$USER /etc/passwd
root:x:0:0:root:/root:/bin/bash
sh-2.05b#

I still get the sh shell.

So, you should see which profile file is being called upon when you login. Just add that line (at the bottom, if you would like to) and you can make your life easy!


All times are GMT -5. The time now is 05:10 PM.