how to use temporary profile when ssh to remote server

Solution 1:

You can use ssh -t to run setup scripts, then a shell, then cleanup scripts. ssh -t allows you to run commands, but still run one or more shells in the middle and allocate a terminal properly

Your setup script can include wget'ing/curl'ing/scp'ing a temporary home directory to something like $HOME/tmphome, then running a script like this to start a shell there:

#!/bin/sh

HOME="$HOME/tmphome"
cd "$HOME"
bash --login

This should do a pretty good job of isolating your rc files to the tmphome, and ssh -t will skip the user's bashrc. As long as your environment is lightweight, it shouldn't take very long to copy.

Your command might be something like ssh -t user@host 'wget http://server/tmphome.tar.gz && tar -zxvf tmphome.tar.gz && rm tmphome.tar.gz && tmphome/shell.sh'

Solution 2:

Why don't you use a distributed version control system like git to store your configuration files ? That's what I do and it works like a charm.