How can i change user name for linux machine in batch file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PrateekThakur
Posts: 6
Joined: 04 Oct 2012 04:43

How can i change user name for linux machine in batch file.

#1 Post by PrateekThakur » 04 Oct 2012 05:22

Hi,

I have batch file which will start plink.exe to login into remote linux machine:

"start C:\Users\279293\Desktop\PLINK.EXE -ssh -P 22 prateek@10.205.198.34 -pw password"

Now i to change username(prateek) to login as webadmin and also providing password. So what I'm doing, i'm appending "echo password-1 ^| sudo su – webadmin " i.e.,

"start C:\Users\279293\Desktop\PLINK.EXE -ssh -P 22 prateek@10.205.198.34 -pw password echo password ^| sudo su – webadmin"

when i execute the batch file it shows the error : Sorry user prateek is not allowed to execute "/bin/su" webadmin as root on webDevprateekpip. Is my batch command is wrong or what?

Thanks...

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How can i change user name for linux machine in batch fi

#2 Post by Squashman » 04 Oct 2012 05:56

I really don't have an answer to your question but I am confused as to why you would use SUDO to run the SU command. The point of the SUDO command is so you don't have to run SU. Been a long time since I was a linux admin so I could just be totally wrong.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How can i change user name for linux machine in batch fi

#3 Post by foxidrive » 04 Oct 2012 06:04

Interesting point, unless he isn't logged in as Root.
The passwords indicated in the script aren't the same...

I don't have an answer either...

PrateekThakur
Posts: 6
Joined: 04 Oct 2012 04:43

Re: How can i change user name for linux machine in batch fi

#4 Post by PrateekThakur » 04 Oct 2012 06:09

@ Squashman : I really don't know about sudo command, infact i'm windows guys just wanted to run batch file in windows which will perform the remote login in linux machine for user "prateek" and then wanted to change login name or login as "webadmin" with password "password". So, what batch command will there to do this.

Thanks for your help.

PrateekThakur
Posts: 6
Joined: 04 Oct 2012 04:43

Re: How can i change user name for linux machine in batch fi

#5 Post by PrateekThakur » 04 Oct 2012 06:10

@foxidrive : Sorry for that, both password are same that is "password".

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How can i change user name for linux machine in batch fi

#6 Post by foxidrive » 04 Oct 2012 06:23

My thought is: why not log in as webadmin to begin with?

You can try an interactive session to see if you can use sudo to perform the login.

http://the.earth.li/~sgtatham/putty/0.5 ... pter7.html


Another point is that piping a phrase through a pipe to an executable isn't always supported by the executable.

PrateekThakur
Posts: 6
Joined: 04 Oct 2012 04:43

Re: How can i change user name for linux machine in batch fi

#7 Post by PrateekThakur » 04 Oct 2012 06:28

@foxidrive : Actually i need to login in that machine by giving my credentials( u: prateek, p: password), then i can login as webadmin which prompt for password that is same password which is for user prateek i.e, password. This all thing can be done with putty , but i want run plink.exe by batch file to do this.

I tried to login as webAdmin directly, but it ask for password then i give same password again and again it is not accepting, saying Access denied.
However when i do manually with putty then it works well.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How can i change user name for linux machine in batch fi

#8 Post by foxidrive » 04 Oct 2012 06:31

If you can't do it with Plink but can do it interactively with Putty then maybe a connection via Plink doesn't have the right permissions, at a guess.

PrateekThakur wrote:I tried to login as webAdmin directly, but it ask for password then i give same password again and again it is not accepting, saying Access denied.
However when i do manually with putty then it works well.


Try it again - be certain you haven't typo'd the password or username.

PrateekThakur
Posts: 6
Joined: 04 Oct 2012 04:43

Re: How can i change user name for linux machine in batch fi

#9 Post by PrateekThakur » 04 Oct 2012 06:41

foxidrive wrote:If you can't do it with Plink but can do it interactively with Putty then maybe a connection via Plink doesn't have the right permissions, at a guess.

PrateekThakur wrote:I tried to login as webAdmin directly, but it ask for password then i give same password again and again it is not accepting, saying Access denied.
However when i do manually with putty then it works well.


Try it again - be certain you haven't typo'd the password or username.



Yeh, you are right password was not correct. Thanks.. So, right now it is not working by both plink or putty, if i directly login as webadmin , same message : Access denied.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How can i change user name for linux machine in batch fi

#10 Post by foxidrive » 04 Oct 2012 07:00

I have no answer - and I don't have the means to test it.

PrateekThakur
Posts: 6
Joined: 04 Oct 2012 04:43

Re: How can i change user name for linux machine in batch fi

#11 Post by PrateekThakur » 04 Oct 2012 09:15

foxidrive wrote:I have no answer - and I don't have the means to test it.


@fordrive : Thanks for your assistance. I got solution for this using Process class in c sharp to automate this process, rather using bath file. And its doing pretty good.

Thanks.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How can i change user name for linux machine in batch fi

#12 Post by Squashman » 04 Oct 2012 11:05

I was always taught to not allow ROOT or any other user with Elevated privileges to login directly with SSH. You login with your normal user and then use SUDO to run any commands that require elevated privileges. That is how all my servers were setup when I was a Linux admin.

Post Reply