sftp script with password as argument [message #246639] |
Thu, 21 June 2007 09:23 |
KrishnaIntel
Messages: 2 Registered: June 2007
|
Junior Member |
|
|
Hey,
I have a shell script, which uses SCP/SFTP to copy the couples files from remote server to local server. It works in interactive mode because I am supplying the password. But not in non-interactive (batch) mode. Is there way to pass the password to the shell script?
Note: I don't wnat to use SSH Config fiel nor Public Private key.
Thanks for your help
|
|
|
Re: sftp script with password as argument [message #246730 is a reply to message #246639] |
Thu, 21 June 2007 13:05 |
DreamzZ
Messages: 1666 Registered: May 2007 Location: Dreamzland
|
Senior Member |
|
|
Quote: | 1. Generate a public and private key pair on the machine from where you want to login to other machines.
For SSH1:
# ssh-keygen -t rsa1
For SSH2 (Recommended):
# ssh-keygen -t dsa
You will be prompted for a file in which the key and a passphrase will be saved. You may press Enter through each of these prompts. If you do so, the key generation program will assume that you wish to use the default file name of id_dsa and your private key will not be protected by a password.
Once this is done, you will see id_rsa and id_rsa.pub in the .ssh directory in your home directory if you have not supplied a file name as I mentioned above.
2. Copy the public keys (id_rsa.pub) to the remote host. This is the host(s) where you wanted to connect without password.
# scp ~/.ssh/id_rsa.pub remote_host:/
3. Login to the remote host and check if you already have authorized_keys file in .ssh dir. If this doesn't exist, create it with the following commands.
# touch ~/.ssh/authorized_keys
4. On the remote host where you are in step 3, copy your public key to the authorized_keys file, with the following command.
# cat ~/ id_rsa.pub >> ~/.ssh/authorized_keys
5. You are set to use SSH authentication without password now. If you want you can delete or move id_rsa.pub file.
You can follow steps 2 - 5 for all other hosts where you want to have public key authentication.
|
|
|
|
Re: sftp script with password as argument [message #246793 is a reply to message #246730] |
Fri, 22 June 2007 00:40 |
KrishnaIntel
Messages: 2 Registered: June 2007
|
Junior Member |
|
|
Hey,
Thank you very mush for the solution, I have already tried with that solution and I have the problem. I need to implement the similar pattern as we give in FTP script
i.e,
ftp
open $ipaddress
user $user $pass
ls
bye
In the same manner I want to use it in the SFTP process. Could you give me the relevant solution without using SSH config nor the Publlic Key generation process.
Thanks & Regards,
Krishna
|
|
|
|
Re: sftp script with password as argument [message #308446 is a reply to message #246973] |
Mon, 24 March 2008 06:09 |
rinku
Messages: 4 Registered: December 2000 Location: India
|
Junior Member |
|
|
hi,
I have the same problem.
I have complete up to this step. After this when I want to run my scripts it gives error , that is
Connecting to remote...
The authenticity of host 'remote_server (remote_server)' can't be established.
RSA key fingerprint is f6:0c:9c:29:be:f6:0d:bb:e2:bc:59:7c:8c:5f:09:3f.
Are you sure you want to continue connecting (yes/no)?
My scripts is like:
FTPHOST4='remote_server'
USER_ID4='userid'
USER_PASSWORD4='password'
echo "Start sftp "
sftp ${USER_ID4}@${FTPHOST4}:${HOME}/priyanka/usr << EOF
lcd ${HOSTFTP_DATA_DIR}
put test.html
quit
EOF
echo "End sftp"
exit
Please help me. I am new in sftp.
|
|
|
Re: sftp script with password as argument [message #463551 is a reply to message #308446] |
Thu, 01 July 2010 15:45 |
DGPickett
Messages: 1 Registered: July 2010 Location: NJ
|
Junior Member |
|
|
Another tack is to make your own sftp or scp with a password passing method that suits your needs. Opinions vary on both the security of trusted public-private key access and the various ways to store and pass passwords. Using the same ssh2 shared libraries makes approach this pretty simple, and examples are easy to Google up:
www.libssh2.org (slash) examples (slash) sftp.html
www.libssh2.org (slash) examples (slash) scp.html
There are perl and JAVA ways to do this too, but the new C++ exe with shared libs seems to be the easiest to deploy and uses the exact same ssh2 code as the original.
|
|
|