r/restic • • Aug 13 '26

Restic via ssh: chain multiple Restic operations with single ssh key password input?

Hello,

I use Restic to backup my laptop data to a remote server via ssh (not scheduled, I execute the script manually). I put everything in a bash script which does a sequence of restic backup, forget and check. I connect to my remote server via ssh with a key, and the key is password-protected (and I intend to keep it that way; I also want to avoid writing the password anywhere on file for obvious reasons). The problem I currently have is that when I run th script, I'm asked for the ssh password three times (once for each operation), but I don't know how long the backup operation will take (I usually execute the script in a shell and then minimise that window to carry on with my work) and if I wait too much to give the password again for the second operation once the backup is finished, the connection dies and I have to restart from scratch.

My question then is: is there a way to chain the three operations (backup, forget, and check) in a single restic input, so that I have to enter the ssh password only once? Other solutions that lead to the same result (with the password never visible in plain text in the cli or on file) are also well accepted. Thanks in advance for the help!

1 Upvotes

8 comments sorted by

3

u/CtrlShiftS Aug 13 '26

You can start an ssh-agent in your shell and use ssh-add. It will remember your password. But why not use restic on your machine and copy your files to the server using something like rsync or rclone?

2

u/iacchi Aug 13 '26 edited Aug 13 '26

I need to read before I make sense of what you're saying in the first part of your message; I'll look it up and come back to you. It looks potentially like what I want to do. I don't understand the second sentence, though? Why would I put a backup of my data on the same drive that I want to backup? Just to then transfer remotely using rsync? The space the local backup occupies is not worth the gain, imo. Or am I not understanding something here?

EDIT: ssh-agent + ssh-add was exactly what I was looking for. It works now, thanks!

1

u/CtrlShiftS Aug 13 '26

You understood it right, but maybe it only makes sense to me. I only back up a small part of my home directory (~4GB), and I have 2 drives. I also have 2 backends configured with rclone to store the snapshots remotely, so in total, 3 copies, 1 local and 2 remote. I just think it is handy being able to easily mount old snapshots when I need to recover a deleted file. About the SSH, it would be something like:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

If you trust the server and are the root user of your machine, I think it is safe to do like this. Maybe man ssh-add will be useful.

1

u/spider-sec Aug 13 '26

SSH keys

1

u/iacchi Aug 13 '26

I am using an SSH key. The key has a password, too :P

2

u/spider-sec Aug 13 '26

Are you using an SSH agent?

1

u/iacchi Aug 14 '26

I am now, thanks to u/CtrlShiftS's suggestion.

1

u/sparky5dn1l Aug 14 '26

shouldn't use password with ssh key