user1227648
user1227648

Reputation: 11

SFTP Connection with out password prompt

I am trying to move txt/ log file from server1 to server2.

I am trying to connect to a server from server1 to server2 using SFTP but some how it is asking for password in the prompt.Can anyone let me know how to give password as input through script and execute this functionality using a Script. Please let me know asap......

MY CODE:

test.sh is script and 1.txt file has password details.....

code: test.sh sftp mwctrl@sacsun11 < 1.txt <> out.log 2>&1 cd /usr/ftadapters/logs/adapters/rivaadp lcd /export/home/eisape put *.txt exit EOF

1.txt: password m33tzn3

Upvotes: 0

Views: 26612

Answers (3)

user1011046
user1011046

Reputation: 204

try using this

/usr/bin/expect <<EOF
spawn sftp -oStrictHostKeyChecking=no -oCheckHostIP=no mwctrl@sacsun11 \
"cd /usr/ftadapters/logs/adapters/rivaadp \
lcd /export/home/eisape \
put *.txt \"
expect "*?assword:*"
send  "m33tzn3"
send  "\r"
set timeout -1
send  "\r"
expect EOF

Upvotes: 0

dopplesoldner
dopplesoldner

Reputation: 9479

Setting up ssh keys is relatively simple. Takes <1 min following the instructions in the link posted above by fxzuz.

But generally passing passwords as parameters / storing in config files is considered a security risk.

However, if you still want to go ahead, here is a link -- http://nixcraft.com/shell-scripting/4489-ssh-passing-unix-login-passwords-through-shell-scripts.html

Upvotes: 0

Pavel Vlasov
Pavel Vlasov

Reputation: 3465

Actually you need add ssh keys to remote machine. Check article below:

Using sftp without password (http://says-story.blogspot.nl/2008/01/using-ssh-scp-sftp-without-password.html)

Upvotes: 2

Related Questions