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.
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?
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.
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.