Can I use ssh to login another host and automatically "su" to another user?

Question

E.g, each time I have start from my mac:

ssh myself@192.168.100.101 to a linux server server and su oracle, and type my password. I wish to accelerate this routine by using some alias, which do the ssh login and su user at the same time.

I know ssh command can do remote command line and quit. But that's not my requirement: I don't wish ssh login/execute/return, I want it to switch user and I start to work.

Any command line option could help on this? Thanks a lot.


Show source
| osx   | linux   | login   | ssh   | su   2017-01-07 04:01 1 Answers

Answers ( 1 )

  1. 2017-01-07 07:01
    ssh -t myself@192.168.100.101 "su oracle"
    

    -t

    Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty

◀ Go back