Github systemclt服务和ssh
我有一个简单的bash脚本,可以调用github上的git存储库(/home/user/simple\u git.sh): 它给出以下输出:Github systemclt服务和ssh,github,ssh,systemd,systemctl,Github,Ssh,Systemd,Systemctl,我有一个简单的bash脚本,可以调用github上的git存储库(/home/user/simple\u git.sh): 它给出以下输出: Local : a10dc1d7d30ed67ed1e514a3c1ffc5a824cea14b Remote: a10dc1d7d30ed67ed1e514a3c1ffc5a824cea14b git身份验证是通过ssh密钥完成的-下面是my.bashrc # ssh eval `ssh-agent -s` ssh-add 该脚本与用户和sudo(通
Local : a10dc1d7d30ed67ed1e514a3c1ffc5a824cea14b
Remote: a10dc1d7d30ed67ed1e514a3c1ffc5a824cea14b
git身份验证是通过ssh密钥完成的-下面是my.bashrc
# ssh
eval `ssh-agent -s`
ssh-add
该脚本与用户和sudo(通过保留用户环境)ie一样运行良好
但是,我还没有找到将脚本作为服务运行的方法(/etc/systemd/user/simple\u git.service或/etc/systemd/system/simple\u git.service)
我已经尝试使用--user选项运行systemctl命令,并修改visudo以包含该行
Defaults env_keep += SSH_AUTH_SOCK
但是没有用。每次检查作业状态时:
Feb 21 23:16:00 alarmpi systemd[484]: Started TestScript.
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: Permission denied (publickey).
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: fatal: Could not read from remote repository.
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: Please make sure you have the correct access rights
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: and the repository exists.
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: Local : a10dc1d7d30ed67ed1e514a3c1ffc5a824cea14b
Systemd没有使用会话中的环境变量运行服务。我建议你去
- 使用git使用
,这将不需要身份验证(而不是https
)ssh
- 创建一个不受保护的“部署密钥”,该密钥将位于标准位置(
),该密钥将由~alarmpi/.ssh/id_rsa
自动获取,而无需git
ssh代理
systemctl--user import environment
。应用此方法后,效果良好。我们在github存储库中使用双因素身份验证,这就是我认为https不起作用的原因。使用不受保护的部署密钥有什么好处?这听起来不是特别安全,但我可能没有抓住要点,我想不必使用ssh代理是一个额外的好处。
[Unit]
Description=TestScript
[Service]
Type=simple
ExecStart=/home/user/simple_git.sh
Defaults env_keep += SSH_AUTH_SOCK
Feb 21 23:16:00 alarmpi systemd[484]: Started TestScript.
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: Permission denied (publickey).
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: fatal: Could not read from remote repository.
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: Please make sure you have the correct access rights
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: and the repository exists.
Feb 21 23:16:01 alarmpi simple_git.sh[15255]: Local : a10dc1d7d30ed67ed1e514a3c1ffc5a824cea14b