[Python] ssh not accepting access with keygen keys

Discussão em 'Python' iniciado por Stack, Março 23, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Desktop plus NAS setup, and did save backups via ssh. It has worked for years, but then the NAS crashed and was replaced. Both desktop and NAS are now regular computers running Linux Mint LMDE6. But now something is wrong in the SSH workings.

    My backup program (https://sourceforge.net/projects/backuso/) needs to be started with sudo, as I need to copy root owned files. SSH is configured with keys to avoid having to enter passwords for the crontab controlled backups. Yet my Python programm is still asking for passwords, like shown here:

    # Python code:
    command = "ssh root@10.0.0.51 'ls \"/home/BackupGen10/BackupRemote/BackusoTEST/\"'"
    proc = subprocess.run(command, text=True, encoding="UTF-8", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

    # shell response:
    root@10.0.0.51's password:


    But when I take this exact same command out of the big Backuso Python code and paste it into a tiny test program, it works perfectly well, NOT asking for passwords, and the output is as it should be:

    Program code:
    #! /usr/bin/python3
    # -*- coding: utf-8 -*-
    import subprocess
    command = "ssh root@10.0.0.51 'ls \"/home/BackupGen10/BackupRemote/BackusoTEST/\"'"
    proc = subprocess.run(command, text=True, encoding="UTF-8", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    print("Items in stdout:")
    for prs in proc.stdout.split("\n"): print(prs)

    Output:
    $ ./test_ssh.py
    Items in stdout:
    2024-06-18_13-53-45-824424
    2024-06-18_13-54-53-855948


    What am I missing?

    Continue reading...

Compartilhe esta Página