Monday, February 4, 2013

LFTP,SFTP password less login Linux to Windows

LFTP can be used as any typical FTP client but it also provides the ability to connect without asking about the password. The solution is simple however a bit unsafe as the password is given explicitly as text, like below. Thus anybody who can read the script can also steal the password, so make sure your script is readable for you only. Also, do not connect as root. Create a special user for this without root super-powers. The example below shows how to get a file from a remote server via secure SFTP protocol (bye at the end closes connection):

lftp sftp://user:password@host:port  -e "get file.name; bye"

We cannot able to upload multiple directories using SFTP but i achieved uploading multiple directories using LFTP,SFTP

Here are the steps i tried to make password less login from linux to windows.

Created the public and private key using putty in windows.

Copied the keys to my linux machine.

Converted the private key to linux key format using puttygen command

puttygen mywinkey.ppk -O private-openssh -o mykey.

Here mywinkey.ppk is the windows private key and mykey is the key created in linux format.

Move mykey file to the .ssh/  folder or copy the key and paste it .ssh/authorized_keys and change its permission

chmod 700 .ssh/authorized_keys

Tried now but prompts for the password, Type Enter key it will enter in to the ftp server

 lftp  sftp://username@sftpservername/
password:

To avoid prompting for password , please follow the below steps.

Enter in to the ftp server and type the below commands

set bmk:save-passwords true
bookmark add testing (Here testing is the bookmark name)
bookmark list


To delete the bookmark, type the below command

bookmark del bookmark name
type help bookmark for more details.


 history -c clears history
                                           
Now we can able to login the windows remote ftp server with out password and avoid prompting for password.


Type

lftp testing 
or
lftp testing sftp"//username@sftpservername.com

For automatic backups also we can use the lftp like rsync .Click here to see more lfp usage commands.

No comments: