Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using the following batch file to log in to my server as root:

start C:\Putty_all\PUTTY.exe -v -ssh root@192.168.32.125 -pw password

When I have logged in, I want to change user to oracle. How do I do that?

share|improve this question
    
That's what su(1) is for. And change that password you published here as soon as possible! –  vonbrand Mar 1 '13 at 10:26

2 Answers 2

You can specifiy commands to be executed on the remote system with the -m <filename> parameter. In the specified file you can have as many commands as you want (one per line).

So you can for example do the following:

set ssh_cmds=%SYSTEMDRIVE%\TEMP\ssh_cmds.txt echo sudo su - oracle > %ssh_cmds% echo whoami >> %ssh_cmds% start %SYSTEMDRIVE%\Putty_all\PUTTY.exe -v -ssh root@192.168.32.125 -pw password -m %ssh_cmds%

This assumes that the user you are logging in with has the ability to use sudo without a password and su to the oracle user.

share|improve this answer
    
Well he's logging in as root, so he won't need a password or sudo. –  Xyon Feb 4 at 13:35

After login, run

su oracle

where su stands for "Switch User" (or something similar);. See man su on the server for more information on the command.

From the root account you don't even need to give the password, since you have full rights on the system.

share|improve this answer
    
no I have to login through that same bat file –  Amit Mar 1 '13 at 10:29

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.