sshuttle 自动化服务运行出现错误

sshuttle 自动化服务运行出现错误

我已经编写了一个服务,因为它是在问题,但是当我运行服务时,我只得到状态错误。

服务:

GNU nano 6.2 /etc/systemd/system/sshuttle.service
[Unit] 描述=sshuttle 隧道

[Service]
Restart=always
User=user
Group=user
ExecStart=/usr/bin/sshuttle -vr my-ip 0/0 -x my-ip/32 --ssh-cmd 'ssh -i ~/server.pem'

[Install]
WantedBy=multi-user.target

我收到的状态错误:

× sshuttle.service - sshuttle tunnel
     Loaded: loaded (/etc/systemd/system/sshuttle.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2023-04-02 11:12:09 +0330; 1s ago
    Process: 2142 ExecStart=/usr/bin/sshuttle -vr my-ip 0/0 -x my-ip/32 --ssh-cmd ssh -i ~/server.pem (code=exited, status=217/USER)
   Main PID: 2142 (code=exited, status=217/USER)
        CPU: 1ms

Apr 02 11:12:09 mj-virtual-machine systemd[1]: sshuttle.service: Scheduled restart job, restart counter is at 5.
Apr 02 11:12:09 mj-virtual-machine systemd[1]: Stopped sshuttle tunnel.
Apr 02 11:12:09 mj-virtual-machine systemd[1]: sshuttle.service: Start request repeated too quickly.
Apr 02 11:12:09 mj-virtual-machine systemd[1]: sshuttle.service: Failed with result 'exit-code'.
Apr 02 11:12:09 mj-virtual-machine systemd[1]: Failed to start sshuttle tunnel.

更新的配置:

[Unit]
Description=sshuttle tunnel

[Service]
Restart=always
ExecStart=/usr/bin/sshuttle -vr ssh-user@ssh-ip 0/0 -x ssh-ip/32 --ssh-cmd 'ssh -i /home/mj/server.pem'

[Install]
WantedBy=multi-user.target

答案1

您的配置中存在一些问题,例如~选项--ssh-cmd

首先这是您的更新ExecStart ExecStart=/usr/bin/sshuttle -vr my-ip 0/0 -x my-ip/32 --ssh-cmd 'ssh -i /home/user/server.pem'然后重新加载您的服务sudo systemctl daemon-reload然后我们启用并启动服务

sudo systemctl enable sshuttle.service
sudo systemctl start sshuttle.service

编辑:

这可能是用户的问题,请确保在下面的文件中 使用正确的文件:

[Unit]
Description=sshuttle tunnel

[Service]
Restart=always
User=<your_username>
Group=<your_groupname>
ExecStart=/usr/bin/sshuttle -vr ssh-user@ssh-ip 0/0 -x ssh-ip/32 --ssh-cmd 'ssh -i /home/<your_username>/server.pem'

[Install]
WantedBy=multi-user.target

答案2

感谢 Saxtheowl,我找到了解决方案

这是我的最终配置并且运行良好:

[Unit]
Description=sshuttle tunnel

[Service]
Restart=always
ExecStart=/bin/bash -c "/usr/bin/sshuttle --dns -vr ssh-user@ssh-ip 0/0 -x ssh-ip/32 --ssh-cmd '/usr/bin/ssh -i /home/ubuntu-user/server.pem -o StrictHostKeyChecking=no'"

[Install]
WantedBy=multi-user.target

相关内容