script accepting password


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script accepting password
# 1  
Old 10-03-2011
script accepting password

Hi friends,
I am very new to Unix scripting and having some difficulty in my first shell script.

I have written a simple shell script to upload an artifact to a remote machine on the network.

Code:
echo "Uploading the artifact"
scp app.war username@remotemochine.domainname.net:/home/deployables

echo "Uploaded the artifacts"

But the issue is it asks for the password once i run the script. Is it possible to write the script in such a way that we can mention the password in the shell script itself and we need not have to enter the password?

Please let me know.

Last edited by prashdeep; 10-03-2011 at 03:21 PM..
# 2  
Old 10-03-2011
ssh, sudo, su, and most other sane login systems are designed to prevent you from using stored plaintext passwords, as they're nearly impossible to keep safe. ssh has a better method.

You can arrange passwordless logins for ssh/scp/sftp with pre-arranged key files. Having the right files in ~/.ssh under the host and server allows 'scp username@host:...' to happen automatically with no modification to your script at all.
# 3  
Old 10-03-2011
Read up on "here documents". Although it is a security risk to have the password in plain text in a file.

Code:
echo "Uploading the artifact" 

scp app.war username@remotemochine.domainname.net:/home/deployables <<EOF
password
EOF

echo "Uploaded the artifacts"

When the called program needs input, it takes it from the text between the EOF's (doesn't have to be "EOF" can be any string you want.).

Yes, don't do this (but check it out for learning purposes). Use Corona688's advice to properly set up the systems instead.
# 4  
Old 10-03-2011
Quote:
Originally Posted by gary_w
Read up on "here documents". Although it is a security risk to have the password in plain text in a file.
That won't work, ever. I wasn't kidding when I said scp, ssh, su, sudo, and most other sane authentication systems are explicitly designed to prevent this -- it's easy for a C program to tell a pipe or file apart from a real terminal, and easier still for a program to just ignore them and talk to the raw terminal itself, /dev/tty, neatly bypassing any redirection. This is because 'interactive password authentication' means 'password typed by a human authentication'.

You'd need to resort to third-party brute-forcing utilities to forcefeed it a plaintext password from file. Fortunately, there's better ways built into ssh as a standard feature: keys.

Last edited by Corona688; 10-03-2011 at 04:51 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Curl not accepting spaces in script via variables

Hi All, I'm trying to run a script which issues rest commands via curl to an endpoint. If I put spaces in fields via something like insomnia, it works, but when I try from an input file, it's failing with a json error. while IFS=, read mname oname <------ my input file... (10 Replies)
Discussion started by: say170
10 Replies

2. Shell Programming and Scripting

Bash script accepting variables in valid number format

Hi Experts I would like to ask if there is a way to validate if the variable passed is in this kind of sample format "06-10" or "10-01". It was really a challenge to me on how to start and echnically the "6-10" stands for "June 10" and "10-01" stands as "October 1", overall it needs to have ... (3 Replies)
Discussion started by: ersan-poguita
3 Replies

3. Shell Programming and Scripting

sed command not accepting variable in shell script

I am using a shell script in fedora linux. While calling to the shell I am also passing an argument (var1=0.77) like shown below sh gossip.sh var1=0.77 in the shell following command is written (which doesn't work) sed - i -e 's@prob=@prob="$var1";//@g' file.txt Actually i want the... (7 Replies)
Discussion started by: Fakhar Hassan
7 Replies

4. Shell Programming and Scripting

SFTP prompting for password even though password is in script

Hi All, I am trying to transfer a file from one server to a remote server using SFTP. Client is not ready for key setup. I am working on Solaris 10. Here is the code. #!/bin/ksh # sample automatic Sftp script to dump a file USER="user1" PASSWORD="pass1" HOST="host1" sftp $USER@$HOST... (6 Replies)
Discussion started by: megha2525
6 Replies

5. Shell Programming and Scripting

Make a password protected bash script resist/refuse “bash -x” when the password is given

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored. The code: read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg... (7 Replies)
Discussion started by: frad
7 Replies

6. Shell Programming and Scripting

Accepting search pattern to script argument

I have a script in tcsh and I want to have a find option to which I can pass a file search pattern I want using the command: /home/chrisd/tatsh/trunk/hstmy/bin/tcsh/raytrac.tcsh -f=*rc* The set command seems to fail when user does not supply a search pattern (if user just supplies -f, a... (2 Replies)
Discussion started by: kristinu
2 Replies

7. Shell Programming and Scripting

Accepting A-Za-Z

Is there a way accept A-Za-z0-9 from the user from a parameter? EX. I want to take the parameter from the user even if its hEu or H3y and store it as a parameter ( $1 ) (18 Replies)
Discussion started by: puttster
18 Replies

8. Shell Programming and Scripting

reg accepting password

Hi, I want to login to many systems and password should be taken automatically from a file(login is working but password is not accepting). Any help on this is appreciable . My code. for i in `cat /tmp/tes ` ====>tes file contain list of hosts > do ssh $i > perl prog.pl >... (1 Reply)
Discussion started by: rogerben
1 Replies

9. Shell Programming and Scripting

how to change root password using shell script with standard password

Hi Friends. I am new to scripting now i want to change the root password using the script with standard password. which is the easy scripting to learn for the beginner, Thanks in advance. (2 Replies)
Discussion started by: kurva
2 Replies

10. Shell Programming and Scripting

invloking another script accepting input

hi I am trying to invoke another application script from my script like --------------------------- main . . ./new appl <<EOF Input 1 Input 2 EOF . . exit ------------------------ But is exits the new application after input command 2, I want that it should not exit and accept... (1 Reply)
Discussion started by: ashish_uiit
1 Replies
Login or Register to Ask a Question