How to provide password to the prompt through Java


 
Thread Tools Search this Thread
Top Forums Programming How to provide password to the prompt through Java
# 1  
Old 11-15-2010
How to provide password to the prompt through Java

Hi All,

I am using Ubuntu machine with JDK 6. I am running following command on shell-

Code:
sudo ./somecript

. Now, it prompts for sudo password and I provide the sudo password on shell and "somescript" starts running with sudo permissions.

What I want to do is, I need to execute "sudo ./somescript" fromJava code. For that I have created a jar file which executes following command
view plaincopy to clipboardprint?
Code:
Runtime.getRuntime.exec("sudo ./somescript");

now, the problem is I dont get any prompt where I can provide the sudo password.

Please guide me to provide password to sudo.


-akash
# 2  
Old 11-15-2010
You don't. It's specifically designed to prevent the use of plaintext passwords as a security feature -- a less-than-subtle hint that what you're attempting is a very bad idea, because stored plaintext passwords are extremely hard to keep safe. Any attempt to shoehorn one in would be very labyrinthine.

You should instead configure sudo to allow this program (and only this program) to be run without a password by this (and only this) user, and make sure this script's options prevent it being modified (so nobody puts anything untoward in it).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

How to provide password for rsync in shell script?

Hi, i want to call the rsync in a shell script so that i can run it in background by passing the password within script itself. Can any one please let me know how can i provide the password in the shell script itself so that rsync will read the password when promted by the script. Its very... (11 Replies)
Discussion started by: Little
11 Replies

2. Shell Programming and Scripting

How to provide password?

Hi , I am trying to unzip some file in a dir using shell script ,but it prompts for password to unzip those files ,how would i provide the passoword in the script it self (1 Reply)
Discussion started by: vikatakavi
1 Replies

3. Shell Programming and Scripting

[Solved] Help with Overriding a Prompt in UNIX/Java

I am executing a shell script which contains a jar call to an external java package for which I don’t have a read access to. The external package was written in such a way that whenever we make a java –jar call to the package, it shows a prompt on the console asking if we want to continue or no... (1 Reply)
Discussion started by: Harry1302
1 Replies

4. Shell Programming and Scripting

Provide Password using to the application using the shell script

Hello, I have a requirement to shut down and start up my application on different environments (Dev, QA and Prod). I have around 24 servers. I have to login to each server manually for shutinng down the application. I wrote a shell command on each server and I am invoking those shell... (2 Replies)
Discussion started by: GDSR Raju
2 Replies

5. Programming

How do i get Java commands to be recognized in command prompt?

I would like to do some of my Java programming homework at home, and when i type things such as "javac" & "java" it does not recognize it. How do i set it up so it recognizes Java coding? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

6. Programming

How do i get Java commands to be recognized in command prompt?

I would like to do some of my Java programming homework at home, and when i type things such as "javac" & "java" it does not recognize it. How do i set it up so it recognizes Java coding? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

7. UNIX for Advanced & Expert Users

Changing the password prompt

Is there any way I can change the prompt which asks for the password on a UNIX system? e.g. When I login using Telnet instead of "Password" I should get "Correct Password". Thanks, Vineet (3 Replies)
Discussion started by: vineetd
3 Replies

8. OS X (Apple)

get around rsync password prompt

Hey there, I'm trying to do a very simple rsync to back up my computer to an external drive connected via usb every night, but it keeps asking for a password. I tried using the password file flag, but it looks like that is only a daemon. Does anyone have any ideas? This has eaten up a lot of my... (4 Replies)
Discussion started by: aarond
4 Replies

9. Shell Programming and Scripting

provide a user password from a script

Hi all, passwd <username> < /var/adm/passwd.txt cat /var/adm/passwd.txt abcd1234 abcd1234 when I run this from the script, it comes with: New password: It is not able to pick from the location /var/adm/passwd.txt. thanks in advance. (6 Replies)
Discussion started by: solaix14
6 Replies
Login or Register to Ask a Question