Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH then change Shell

Tags:

Potentially a real easy question but I was wondering if anybody can kindly provide some advice.

To accomplish a repeating task, I am constantly logging into a remote Solaris server using credentials given to us from our system admin. However, each time I log in, I must change shell (from csh -> bash) as the specific task must be run using BASH.

Although it is not a major problem doing this, I find the changing to bash shell somewhat tedious as I must repeat this task several times a day, and also occasionally may forget to change shells before running the task, etc (also I prefer BASH too so).

Is there a way where I can ssh and change default shell in one line so I can start immediately with the script I want on the remote server? Note, I do not what to change any log in files (like .login or .cshrc) as the remote server & the credentials are shared an not specifically for me. I don't want to change the default shell either on the server either as, again, the server & the credentials are used by several people.

Would anybody have any ideas how to get around such a problem? Any suggestions would be greatly appreciated.

like image 954
user2511875 Avatar asked Jul 28 '14 10:07

user2511875


People also ask

How do you switch to another shell?

To change your shell use the chsh command: The chsh command changes the login shell of your username. When altering a login shell, the chsh command displays the current login shell and then prompts for the new one.

How do I SSH into bash shell?

Go to Connection > SSH and set the Remote command to bash . Note that you won't be able to exit to your default shell, it will just close the connection.

Which shell is used by SSH?

SSH, also known as Secure Shell or Secure Socket Shell, is a network protocol that gives users, particularly system administrators, a secure way to access a computer over an unsecured network. SSH also refers to the suite of utilities that implement the SSH protocol.


1 Answers

SSH usually executes the command you pass it as an argument and then disconnects. You'll need three options set to get your interactive session to work:

  • ssh -t will force the pseudo-tty allocation necessary for you to interact with the remote command you're asking SSH to run
  • bash -l will start an interactive login shell
  • csh -l -c will start an interactive login shell in csh, and then execute the command that follows

To just launch a different shell (i.e., your default is csh, and you want to launch bash):

ssh -t <user>@<server> "bash -l" 

To pickup the csh environment first, we start the interactive shell, and then pass the command to switch to bash:

ssh -t <user>@<server> 'csh -l -c "bash"' 
like image 148
Beggarman Avatar answered Nov 22 '22 22:11

Beggarman