At work our team uses a shared account "appadmin" to administer our application. At login, each one of us sources an "aliasrc" file containing his or her preferences. (aliases, display, prompt, ...).

So far I do something like this:

normaluser$ su - appadmin
appadmin$ . ~normaluser/.aliasrc
[superprompt: appadmin@machine]$ 

I am looking to reduce all this to a single command. So far I have replaced the use of su by rlogin in order to take advantage of .rhosts and avoid having to input the password each time. (I know ssh is secure, but rlogin seems to be the standard around here).

Is there a way to source my aliasrc file as soon as I login in the shared account?

I don't insist on using rlogin. If you have something better to suggest I am all ears (... well eyes :-/ ).

Hope I am clear enough.

Technical environment: Solaris 10, Ksh.


You want to add something to ~appadmin/.profile or another login script that will load .aliasrc based on who you were before switching users. The hard part is figuring out that username, since the usual methods aren't going to work:

$ whoami

$ id
uid=1050(appadmin) gid=1050(appadmin)

$ id -ru

I think the easiest way is to figure out which tty you're on (with the tty command), and check which user owns it -- that should be the user you connected as:

$ stat -c %U $(tty)

Then you can just make sure ~normaluser/.aliasrc exists, and source it if so:

origuser=$(stat -c %U $(tty))
[ -e ~$origuser/.aliasrc ] && . ~$origuser/.aliasrc
  • You'll probably want to check whether it is readable with -r rather than if it merely exists. – Chris Down Sep 20 '11 at 18:17
  • 1
    It's not working :( The command stat -c %U $(tty) always returns "root". – rahmu Sep 21 '11 at 9:21

Okay.. I'm not familiar enough with rlogin or ksh, but this works with bash and ssh

  1. create touch .ssh/authorized_keys file for appadmin and chmod -R og-rwx .ssh
  2. for each user create public/priveta ssh keys with ssh-keygen
  3. append your sshkeys public part (like id_rsa.pub) to appadmins authorized_keys
  4. check that you can login with out password (passphrase is different and you should use it)
  5. if login worked ok, add this to your line in authorized_keys before your key

    command="bash --rcfile /path/to/your/.profile" AAAA… rahmu@example.com
  6. if everything worked ok, you should now have your session with your aliases. Also maintaining access to appadmin is relatively straightforward and as long as users use passphrase for ssh-keys it adds a bit more protection than palin old rlogin

Howto configure/generate ssh-keys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.