r/linuxadmin • • Jan 22 '26

rsync --server question

Hi,

I need to sync file between two hosts with rsync+ssh using private key. After key sharing I restrict the key to only one command: "/usr/bin/rsync --server -slHDtprze.iLsfxCIvu". It works, but I've a problem. If I try to connect to the host using the specified key but not using rsync it will hangs forever. There is a way to specifity to rsync a timeout when using --server or something similar?

Thank you in advance

11 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/michaelpaoli Jan 22 '26

If you've got forced command configured with that key on the server, however you use that user and key on that server, you get that forced command - even if you're not using rsync on the client, so yeah, if you, e.g. do a regular interactive ssh session with that key, unless you're fluent in rsync dialog, you won't get very far.

So, use a different key, or use a different forced command, e.g. wrapper program, so you can vary what's executed, depending what command you specify from the client.

I'm sure I've got examples around, let's see if I have a simple one - or maybe I just create one ...

$ id -nu
test
$ cd ~/.ssh
$ ssh-keygen
// ...
awk '{print $1,$2}' id_ed25519.pub > authorized_keys
$ ssh -nT ::1 '/bin/echo A'
A
$ ssh -nT ::1 '/bin/echo B'
B
$ ex authorized_keys
authorized_keys: unmodified: line 1
:s/^/command="\/bin\/echo Z" /
command="/bin/echo Z" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMGwujJFJroQ+YK/SPwEq+
2/unwrtKMvsx7cUQ4Jt17U
:wq
authorized_keys: 1 lines, 103 characters
$ ssh -nT ::1
Z
$ ssh -nT ::1 '/bin/echo A'
Z
$ ex authorized_keys
authorized_keys: unmodified: line 1
:s/^.*"/command="case \\"$SSH_ORIGINAL_COMMAND\\" in [AB]) echo $SSH_ORIGINAL_COMMAND;; *) echo 'A or B only';; esac"
command="case \"$SSH_ORIGINAL_COMMAND\" in [AB]) echo $SSH_ORIGINAL_COMMAND;; *)
 echo 'A or B only';; esac" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMGwujJFJroQ+YK/
SPwEq+2/unwrtKMvsx7cUQ4Jt17U
:wq
authorized_keys: 1 lines, 189 characters
$ ssh -nT ::1 A
A
$ ssh -nT ::1 B
B
$ ssh -nT ::1 C
A or B only
$ ssh -nT ::1 /bin/sh
A or B only
$ ssh -nT ::1
A or B only
$ 

So, e.g., you could code such that, depending upon SSH_ORIGINAL_COMMAND, it could exec rsync with relevant arguments, or user's shell suitably invoked, or perhaps even just stubbornly complain and return an error.