ssh & load custom profile

i've created a custom profile that contains custom functions and alias' etc...

it's called .jason_profile

currently we ssh to the server then load the profile manually from the cmd line i.e

. /home/jack/.jack_profile

we want to be able to ssh and source the profile automatically but without having it added to bash_profile or bashrc. the reason for this is there are many users on this box and they dont necessarily want to inherit this custom profile

was hoping to get this working via ssh i.e

ssh -t $USER@$HOST "source /home/jack/.jack_profile;bash"

this doesnt work as by virtue of calling bash, we overwrite everything jack_profile sets.
yet i have to invoke bash else the ssh doesnt work (it logs on, executes the profile, bombs out back to the previous cmd prompt on the previous host)

also tried:

ssh -t $USER@$HOST "bash;source /home/jack/.jack_profile"

so how can i load this custom profile automatically without everyone inheriting it?

had a read at a few threads such as how to stay in remote shell after executing commands in ssh? - The UNIX and Linux Forums but couldnt find the answer

---------- Post updated at 10:19 AM ---------- Previous update was at 10:08 AM ----------

ok got it working with

ssh -t $USER@$HOST "bash --rcfile /home/jack/.jack_profile -i"

now need to do above + cd into a dir. below doesnt work

ssh -t $USER@$HOST "bash --rcfile /home/jack/.jack_profile -i;cd /etc"

Your specifications need some detail, in order for us to help.

  1. Do the users who need the custom profile always want to have it available?
  2. Are there identifiable user groups or user ids that need the profile?
  3. What happens to a user who accidentally gets the profile - what breaks?
  4. Are you doing ANYTHING in the profile to change the set of standard UNIX commands,
    aliases for commands, PATH changes? (so that some scripts you don't know about will fail, for example)
  1. yes
  2. there is a powerbroker group that they can sudo into but currently they are sudo'ing into the service account via ssh
  3. the user will lose their own custom profile that they would have applied similar to how we apply ours. they would need to re-apply their custom profile should they accidently inherit ours.
  4. no. the custom profile consists of aliases and functions designed to perform purpose built tasks. we have been running this profile for a few months without adverse effects

thanks for looking into this

You need either a list of user id's (numeric) or group ids (numeric) on the remote box. The example uses group ids

Call it /path/to/id.txt. I am assuming a POSIX compliant system

[ "$(awk -v me=$(id -g) 'me==$0 {print 1}' /path/to/id .txt )" ]  && source /path/to/.jack_profile

On the remote box:

Add the above line in a common file /etc/profile or add it to some other globally executed login script. Be sure to test first before placing it in "login" files.

Note: "source" works only with bash, you can use a lonely leading dot instead.

You can modify .jack_profile to do the same check and just simply put it in some global file. All you do to maintain it is edit the /path/ti/id.txt file.

Hi Jim thanks for the response
I found a way to do this via ssh, see my edit above.
The only outstanding part is being able to cd into a directory passed as a parameter in the ssh -t command