Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
password:
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.

share|improve this question

2 Answers 2

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

share|improve this answer

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
appadmin

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

$ id -ru
1050

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)
normaluser

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

origuser=$(stat -c %U $(tty))
[ -e ~$origuser/.aliasrc ] && . ~$origuser/.aliasrc
share|improve this answer
    
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
    
It's not working :( The command stat -c %U $(tty) always returns "root". –  rahmu Sep 21 '11 at 9:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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