I'm diving into Linux while working on a class project involving honeypots. I need to set up a systemd service to automatically start my Python honeypot script every time the system boots up. It needs root access since it's listening to network ports. Can anyone guide me on how to get systemd to launch this script in a terminal GUI so I can see real-time output?
4 Answers
I get that you're eager to learn, but make sure you’re aware of the risks involved here. This might not be the right project for someone who's still getting the hang of Linux. That said, it sounds like you're conducting a class experiment, so be careful and ensure you understand all commands before executing them. It might help to work in a VM like you mentioned!
To create the systemd service, you’ll want to head over to `/etc/systemd/system/` and create a service file, like `myscript.service`. Fill it with the following:
```
[Unit]
Description=My Python Script Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /path/to/your/script.py
Restart=always
User=root
WorkingDirectory=/path/to/script/directory
[Install]
WantedBy=multi-user.target
```
After that, run `sudo systemctl daemon-reload` to apply the changes. To enable it at startup, use `sudo systemctl enable myscript.service` and start it with `sudo systemctl start myscript.service`. Good luck with your project!
You can actually take advantage of a TMUX session for your script. Here's the basic idea: create a TMUX session that runs your script, and then you can attach to that session whenever you need to check the output. If you just want the output and no interaction, it might be better to log the output to a file and then start another service that runs `tail -f` on the log file. This way, you'll still get to see the live updates without needing a terminal GUI.
While I respect your enthusiasm, running a honeypot can be risky if you're not careful. If you must proceed, consider using `AmbientCapabilities=CAP_NET_BIND_SERVICE` in your service file instead of running the whole script as root. It's still a smart idea to isolate the script as much as possible to minimize potential damage.
Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures