You are not logged in.

#1 2016-09-03 17:07:04

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Having systemd user timer run rsync using my personal config file

I have created a user timer in the listed folder.

╔═[12:08]═[inxsible @ moralltach]
╚═══===═══[~/.config/systemd/user]>> la
total 8.0K
-rw-r--r-- 1 inxsible inxsible 172 Aug 28 20:42 backupDocuments.service
-rw-r--r-- 1 inxsible inxsible 112 Sep  3 11:59 backupDocuments.timer

Based on the logs below, it seems that the timer is called correctly, but since I have ssh keys for all my ssh logins, the timer doesn't seem to pick up my .ssh/config file which lists what key & port to use for which of my 3 servers. How would I tell the rsync called by user timer to use my .ssh/config file ?

-- Logs begin at Sat 2015-03-21 19:27:43 CDT, end at Sat 2016-09-03 12:01:55 CDT. --
Sep 03 11:59:52 moralltach systemd[962]: Started Timer for backing up documents.
Sep 03 12:01:07 moralltach sudo[11490]:  inxsible : TTY=unknown ; PWD=/home/inxsible ; USER=root ; COMMAND=/usr/bin/hddtemp /dev/sda1
Sep 03 12:01:07 moralltach sudo[11490]: pam_unix(sudo:session): session opened for user root by (uid=0)
Sep 03 12:01:07 moralltach sudo[11490]: pam_unix(sudo:session): session closed for user root
Sep 03 12:01:55 moralltach systemd[962]: Started Sync documents to al-khadim.
Sep 03 12:01:55 moralltach rsync[11700]: Arch Linux \r (\l)
Sep 03 12:01:55 moralltach rsync[11700]: Permission denied (publickey).
Sep 03 12:01:55 moralltach systemd[962]: backupDocuments.service: Main process exited, code=exited, status=255/n/a
Sep 03 12:01:55 moralltach rsync[11700]: rsync: connection unexpectedly closed (0 bytes received so far) [sender]
Sep 03 12:01:55 moralltach rsync[11700]: rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.2]
Sep 03 12:01:55 moralltach systemd[962]: backupDocuments.service: Unit entered failed state.
Sep 03 12:01:55 moralltach systemd[962]: backupDocuments.service: Failed with result 'exit-code'.

Note that if I call rsync directly(outside of the timer/service), it picks up the config file and the transfer works perfectly. I had initially created a system wide timer -- which failed because it tried to connect to port 22 wihch is why I created a user timer.

Edit : Forgot to mention that I have an ssh agent running and I have already added the keys to the agent when I logged in.

Last edited by Inxsible (2016-09-06 19:54:41)


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#2 2016-09-06 19:55:00

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Having systemd user timer run rsync using my personal config file

any insights on this, please ?


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#3 2016-09-06 20:34:51

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Having systemd user timer run rsync using my personal config file

I'm guessing you haven't imported the necessary variables into the user service manager's environment, so child processes do not see the ssh agent.

Offline

#4 2016-09-06 23:59:07

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Having systemd user timer run rsync using my personal config file

Try adding this under the [Service] section of your .service file

Environment=SSH_AUTH_SOCK=/run/user/1000/ssh_auth_sock

Scott

Offline

#5 2016-09-14 01:36:44

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Having systemd user timer run rsync using my personal config file

Thanks firecat53, but that doesn't seem to change anything. I still get the same failure in the logs and no updates of my changed files over on the server. sad

Raynman, I believe you were saying the same thing about importing the environment variables.

Sep 13 20:46:49 moralltach rsync[10426]: Arch Linux \r (\l)
Sep 13 20:46:49 moralltach rsync[10426]: Permission denied (publickey).
Sep 13 20:46:49 moralltach rsync[10426]: rsync: connection unexpectedly closed (0 bytes received so far) [sender]
Sep 13 20:46:49 moralltach rsync[10426]: rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.2]
Sep 13 20:46:49 moralltach systemd[484]: syncAlKhadim.service: Main process exited, code=exited, status=255/n/a
Sep 13 20:46:49 moralltach systemd[484]: syncAlKhadim.service: Unit entered failed state.
Sep 13 20:46:49 moralltach systemd[484]: syncAlKhadim.service: Failed with result 'exit-code'.

Last edited by Inxsible (2016-09-14 01:42:23)


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#6 2016-09-14 08:24:20

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Having systemd user timer run rsync using my personal config file

Inxsible wrote:

Raynman, I believe you were saying the same thing about importing the environment variables.

Well, I don't know if that is the correct (and only) variable for your user (perhaps you need to look at this further?) and I would consider not hardcoding the value, but that was the general idea, yes.

To clarify: you have the thread title and

How would I tell the rsync called by user timer to use my .ssh/config file ?

but also

my .ssh/config file which lists what key & port to use

and

I had initially created a system wide timer -- which failed because it tried to connect to port 22 wihch is why I created a user timer.

This implies you had a different error with the system-wide timer and it does now in fact pick up the port setting from the user config, but it fails at the next step (public key authentication)?

Offline

#7 2016-09-15 17:11:59

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Having systemd user timer run rsync using my personal config file

Raynman,

IIRC, I believe in the error message, it said that it cannot connect to port 22 -- which is why I thought, that since my ssh config file is under my user name, the root user will of course not be able to access it and was therefore trying to connect to the default ssh port of 22.

I will try and re-create the system wide timer and post the exact error message.

If rsync is picking up the port from the config file, as you say, then why would it not pick up the key information which is in the same config file too? I also mentioned in my first post that using rsync outside of the timer(user or otherwise) seems to work as expected.

Last edited by Inxsible (2016-09-15 17:14:58)


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#8 2016-09-15 17:34:50

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Having systemd user timer run rsync using my personal config file

Inxsible wrote:

If rsync is picking up the port from the config file, as you say, then why would it not pick up the key information which is in the same config file too?

It seems impossible that it would pick up only part of the config. That is why I thought the ssh-agent would be the likely source of the problem. The config says which key to use, but if that key needs a password, the service, running non-interactively, would probably fail (without access to the ssh-agent).

The error message ("Permission denied (publickey).") is not particularly detailed, but I don't know what else it could be. Maybe you could test with a passwordless key?

Last edited by Raynman (2016-09-15 17:35:29)

Offline

#9 2016-09-16 14:17:08

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Having systemd user timer run rsync using my personal config file

Makes sense... will post the results after some more testing. Thanks


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

Board footer

Powered by FluxBB