Reputation: 394
I want to login to an interactive shell on a server using SSH and, after logging in, execute two commands.
This works: ssh user1@server -t "cd /home/user2; bash --login"
None of the following work:
ssh user1@server -t "cd /home/user2; bash --login -c 'source /home/user2/.bashrc'"
ssh user1@server -t "cd /home/user2; bash --login -c source /home/user2/.bashrc"
ssh user1@server -t "cd /home/user2; bash --login source /home/user2/.bashrc"
ssh user1@server -t "cd /home/user2; bash --login; source /home/user2/.bashrc"
When I call ssh with the -v flag, I see the following before the ssh session exits:
debug1: Sending command: cd /home/user2; bash --login -c "source /home/user2/.bashrc"
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
I know this might look odd; I need to login as user1 so that I can use software (legally) that can only be run by user1, but I want to run my personal .bashrc and work in my personal working directory. I can not modify /home/user1/.bashrc. Is there any better way to do what I'm trying to do?
Upvotes: 1
Views: 2278
Reputation: 17169
I might be missing something but in order to achieve the stated goal:
it is enough to say
ssh user1@server -t "cd /home/user2; bash --rcfile /home/user2/.bashrc -i"
Note that in most cases this would work without the -i
and without giving the full path to .bashrc:
ssh user1@server -t "cd /home/user2; bash --rcfile .bashrc "
Upvotes: 3