CodexBloom - Programming Q&A Platform

Fedora 37 - Service scenarios to Retrieve Configuration from Remote Git Repository with 'Permission Denied'

πŸ‘€ Views: 34 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-10
linux systemd git fedora bash

I'm running a service on Fedora 37 that needs to pull configuration files from a private Git repository hosted on GitHub. However, when I try to start the service, I encounter a 'Permission Denied' behavior. The service is defined in systemd and is supposed to execute a script that performs a `git clone` operation. I have set up SSH keys for my user and added the public key to my GitHub account, but it seems like the service does not have access to the SSH agent. Here’s the relevant part of my service definition: ```ini [Service] Type=simple User=myuser WorkingDirectory=/path/to/working/directory ExecStart=/path/to/my/script.sh Environment=SSH_AUTH_SOCK=/run/user/1000/ssh/agent.sock ``` In my script (`script.sh`), I'm using the following command to pull the repository: ```bash #!/bin/bash # Attempt to clone the repository git clone git@github.com:myuser/my-private-repo.git ``` When I run the script manually as `myuser`, it works perfectly and clones the repository without any issues. However, when systemd tries to execute it, I see the following behavior in the journal log: ``` Failed to start my-service.service: Process /path/to/my/script.sh exited with status 128. Cloning into 'my-private-repo'... fatal: Could not read from remote repository. ``` I've confirmed that the `SSH_AUTH_SOCK` is set correctly and that the SSH key is valid. I've also tried changing the permission of the `.ssh` folder and the `id_rsa` file to ensure they are not too open. The user has access to the SSH agent, but somehow it seems that the service want to retrieve it when running under systemd. I've tried adding `EnvironmentFile` to specify the SSH agent, but nothing seems to work. Any suggestions on how to resolve this?