ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a script i need to sftp to anoother server, and sftp is the only thing i can use. Im to script username and password but still keep getting prompted for the password. Can someone tell me what needs to be changed?
Thanks!
#!/bin/sh
HOST='IP of dest svr'
USER='userid'
PASSWD='passwd'
sftp ${HOST} << EOF
user {$USER} {$PASSWD}
lcd /home/userid
put test.txt
exit
It's probably using PAM to get the password, which tends to read its input directly from the terminal bypassing the standard input stream, so tricks like "echo $PASS | sftp ..." won't work. You could fool it by messing around with pseudo-ttys, but I've always found them rather hard to work with.
A much easier solution would be to set up public key authentication, as described here: http://sial.org/howto/openssh/publickey-auth/ (nb: the sftp program actually uses ssh as its transport layer, hence the talk of ssh in the howto).
But in order for this to work, doesn't sshd_config on the remote server have to have a option set to allow for passwordless authentification? I on the server im trying to run sftp from i did "ssh-keyget -t rsa and dsa" and cat'ted them into an authorized_keys file on the server and then scp'd that auth_keys file to the remote server and then tried to sftp the file over i am trying to transfer and still got prompted for the password.
So is my mistake in how i generated the keys and moved the auth_keys file to the remote server or is it the option in sshd_config? If its the sshd_config file then im SOL cause i dont have access to it because it isnt my server and its locked down like a drum.
Well, you shouldn't really put usernames/passwds in scripts, as this is a definite security risk.
That being said, you can use the 'expect' utility to automate the passwd handling.
Possibly also look at ssh-agent : http://mah.everybody.org/docs/ssh
Yea i know i shouldnt but this is at the clients request because it is a pretty harmless server so if it did get hacked, no biggie. So anyone know how to get around the usernam and passwd issue with sftp?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.