Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[Software] lftp: script from root should load private key from user

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
GabrieleMax
Posts: 126
Joined: 2016-09-07 20:24
Location: Senigallia (AN) - Italy
Has thanked: 4 times
Been thanked: 1 time
Contact:

[Software] lftp: script from root should load private key from user

#1 Post by GabrieleMax »

Hi guys,

I need to do a script to upload file by lftp to a remote sftp server by the use of private\public key without password; I generated the keys from a normal user and if I use the script from the normal user it works but I should crontab the script from root who by default can't read the key of the user so I should add a line to "redirect it"!

Here below there's the script which, like what I said above, works from the normal user environment:

Code: Select all

HOST='sftp://remote_ip:remote_port'
USER='ftp_username'
PASS='password'
TARGETFOLDER='/remote_folder'
SOURCEFOLDER='/home/user/upload'
lftp -c "
set ftp:ssl-allow no
open $HOST
user $USER $PASS
mirror -R --verbose $SOURCEFOLDER $TARGETFOLDER
bye
"
Regards.
GabrieleMax

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: [Software] lftp: script from root should load private key from user

#2 Post by reinob »

why use lftp for sftp?
you could use rsync over ssh, and with it you can pass any key (identity),
something like:

Code: Select all

rsync -av -e "ssh -i /path/to/your/.ssh/key" username@hostname:/from/ /to/
(note that in the example above you use a password, so I'm confused as to what exactly you want to have)

GabrieleMax
Posts: 126
Joined: 2016-09-07 20:24
Location: Senigallia (AN) - Italy
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: [Software] lftp: script from root should load private key from user

#3 Post by GabrieleMax »

reinob wrote: 2023-01-24 15:45 why use lftp for sftp?
Because the remote sftp server is on Windows o.s. and it doesn't work obviously with all linux commands... :\
reinob wrote: 2023-01-24 15:45 you could use rsync over ssh, and with it you can pass any key (identity),
something like:
Linux to Linux I could use also scp but, like what I wrote above, I don't know if rsync could work on Microsoft O.S.
reinob wrote: 2023-01-24 15:45 (note that in the example above you use a password, so I'm confused as to what exactly you want to have)
I wrote the word "password" because lftp wants it when you have passwordless, if you doesn't add it the remote system requires to insert it also if the remote public it doesn't have it!

Regards.
GabrieleMax

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: [Software] lftp: script from root should load private key from user

#4 Post by reinob »

OK, I guess I assumed linux-to-linux :)

But at least lftp appears to support giving it a "connect program", with the option sftp:server-program, so you could try adding:

Code: Select all

sftp:connect-program "sftp -i /path/to/identity"
and I suppose that you could add the username to the HOST variable:

Code: Select all

HOST="sftp://ftp_username@remote_ip:remote_port"
Whether this still requires a (dummy) password or not.. it seems you have a weird SFTP server on the Windows side..

GabrieleMax
Posts: 126
Joined: 2016-09-07 20:24
Location: Senigallia (AN) - Italy
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: [Software] lftp: script from root should load private key from user

#5 Post by GabrieleMax »

reinob wrote: 2023-01-24 17:29 OK, I guess I assumed linux-to-linux :)
In a wonderful world everyone should use Linux distros! :)
reinob wrote: 2023-01-24 17:29 But at least lftp appears to support giving it a "connect program", with the option sftp:server-program, so you could try adding:

Code: Select all

sftp:connect-program "sftp -i /path/to/identity"
and I suppose that you could add the username to the HOST variable:

Code: Select all

HOST="sftp://ftp_username@remote_ip:remote_port"
Now I can't test it because I don't have a test environment and I can't use the production server but I understood I could do something like this:

Code: Select all

sftp:connect-program "sftp -i /path/to/identity"
HOST='sftp://remote_ip:remote_port'
USER='ftp_username'
PASS='password'
TARGETFOLDER='/remote_folder'
SOURCEFOLDER='/home/user/upload'
lftp -c "
set ftp:ssl-allow no
open $HOST
user $USER $PASS
mirror -R --verbose $SOURCEFOLDER $TARGETFOLDER
bye
"
I think I don't need to insert the username like what you wrote above so I can get it from the variable maybe I should use a variable also for sftp:connect-program "sftp -i /path/to/identity" and insert it before open command...
reinob wrote: 2023-01-24 17:29 Whether this still requires a (dummy) password or not.. it seems you have a weird SFTP server on the Windows side..
Its name is Syncplify.me

Regards.
GabrieleMax

Post Reply