Find the answer to your Linux question:
Results 1 to 1 of 1
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Bash Rsync over ssh with key issues


    Hey group so this is something I have been trying to get to work for a while and it is kicking my butt.

    This script is called by qbittorrent checks if something is categorized then performs one of two rsyncs to move it to another server. $1 is the full file path, $2 is the category

    USER-AT-SERVER is what it should be for the local server, for some reason the forum thinks I'm posting an html link.


    Code:
    #!/bin/bash
    
    
    
    
    # was used to troubleshoot variables
    echo "$2" >> /var/log/test.log
    
    
    #
    #
    #################################### file logic if statements to sort according                                                                             
    #
    #
    # check  if app cat, move to zip-folder & delete source
        if [ "$2" = "app" ]; then
           rsync -e "ssh -i /home/user/.ssh/id_rsa" -avz --remove-source-files "$1" USER-AT-SERVER:/mnt/storage/media/zip-folder/incoming &>> /var/log/test.log
           find /mnt/storage/downloads -mindepth 1 -type d -empty -delete
        else
    # check if music move to unsorted music
        if [ "$2" = "music" ]; then
           #echo "tested correct for music"  &>> /var/log/test.log
           rsync -e "ssh -i /home/user/.ssh/id_rsa" -avz --remove-source-files "$1" USER-AT-SERVER:/mnt/storage/media/mp3s/incoming &>> /var/log/test.log
           find /mnt/storage/downloads -mindepth 1 -type d -empty -delete
        else
           echo "not music" &>> /var/log/test.log
        fi
        fi
    So this works fine when run by hand but for some reason will not run when called by qbittorrent. The variables get set, but it seems to get hung up on the ssh part of the command.

    I've tried to change the rsync command up a few different ways. I had it like this as well
    Code:
    rsync -avz --remove-source-files -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress "$1" USER-AT-SERVER:/mnt/storage/media/zip-folder/incoming &>> /var/log/test.log
    (first results below, second in the log are the results from the posted entire script, both triggered by qbittorrent)

    Code:
    music
    opening connection using: ssh -i /home/user/.ssh/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -l david 192.168.1.125 rsync --server -vvlogDtprze.iLsfxC --remove-source-files . /mnt/storage/media/mp3s/incoming  (16 args)
    Warning: Permanently added 'IP NUMBER' (ECDSA) to the list of known hosts.
    Permission denied, please try again.
    Permission denied, please try again.
    Permission denied (publickey,password).
    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: error in rsync protocol data stream (code 12) at io.c(235) [sender=3.1.2]
    
    music
    Permission denied, please try again.
    Permission denied, please try again.
    Permission denied (publickey,password).
    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: error in rsync protocol data stream (code 12) at io.c(235) [sender=3.1.2]
    Qbittorrent is running as user, and the id_rsa key works fine manually with ssh and using the script in a shell. Please linuxforums can someone tell me what I'm doing wrong?


    EDIT:
    So I tried it with a key with no password and that worked so it appears ssh-agent doesn't forward the key password when ssh is called by rsync. Can anyone give me a hint if these can work together or should I just give up and use a insecure key?

    Thanks in advance.
    Last edited by dpreviti; 3 Weeks Ago at 06:44 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •