You can temporarily copy your .bashrc
to your remote machine with another name. For example, using .bashrc_temp
:
user@local$ scp .bashrc user@remote:~/.bashrc_temp
Afterwards you can log into the remote machine:
user@local$ ssh user@remote
and source
the file .bashrc_temp
:
user@remote$ source ~/.bashrc_temp
Now you are able to use your .bashrc
and your functions. When you are finished with your work you can remove the file ~/.bashrc_temp on the remote machine and logout.
The copying of the file and the login to the remote machine may be achieved with a bash function:
# copy the .bashrc to the remote machine
# and log into the remote machine.
# parameter $1: user@remote
function s() {
scp ~/.bashrc $1:~/.bashrc_temp
ssh $1
}
Update:
You may also consider to copy the .bashrc
to /tmp
on your remote machine and source /tmp/.bashrc_temp
.
Update 2:
You can log into the remote machine by using ssh -t. This will automatically use your temp .bashrc
. Updated function s()
:
function s() {
scp ~/.bashrc $1:/tmp/.bashrc_temp
ssh -t $1 "bash --rcfile /tmp/.bashrc_temp ; rm /tmp/.bashrc_temp"
}
5Almost all answers (including this one) use predictable filename in
/tmp/
. This can trivially be exploited by any other user to run any code as a user which logs in. This should usemktemp
to make sure the temporary file has an unique name. – Tometzky – 2018-01-22T23:57:18.880This is definitely what I'm looking for. Thanks! But is it possible to do it more functional? In one step? Because now we need 3 steps: log in, source, delete before logout. – None – 2012-11-09T03:22:35.217
OK, I see now after your update. Great. One more fix: "bash --rcfile /tmp/.bashrc_temp; rm /tmp/.bashrc_temp" – None – 2012-11-09T15:29:41.233
I have added your fix to my update 2. Thanks. – None – 2012-11-09T16:23:10.650