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

1.8k Views Asked by At

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

ssh [email protected] 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.

1

There are 1 best solutions below

0
On BEST ANSWER
ssh -t [email protected] "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