Should be as easy as executing the script from the .profile of root - that means if "log in as root" actually means root, not just sudo'ing. .profile will always be read as soon as the user logs in, no matter how. Through a terminal, a GUI, doesn't matter. No idea if doing this through systemd is even possible.
Best Richard On Mon, May 13, 2024, 04:10 Mario Marietto <marietto2...@gmail.com> wrote: > Hello to everyone. > > I'm using Debian 12. I'm configuring a little Debian 12 vm with qemu that > I will use to forward the cloudflare connection to FreeBD. > What I want to do is to run the script below as soon as root has logged > in. > > I've configured the automatic login of root adding to this service file : > > nano /etc/systemd/system/getty.target.wants/getty@tty1.service > > this line : > > ExecStart=/sbin/agetty -o '-p -f -- \\u" --noclear --autologin root %I > $TERM > > Now,what I want to do is that the script below is ran as soon root is able > to logged in automatically : > > /usr/bin/warp > > warp-cli disconnect > echo 1 > /proc/sys/net/ipv4/ip_forward > iptables -A POSTROUTING -t nat -s 192.168.1.5 -j MASQUERADE > OLD_IP="$(curl -s api.ipify.org)" > warp-cli connect > NEW_IP="$(curl -s api.ipify.org)" > echo Connected to Cloudflare Warp... > echo OLD IP is : $OLD_IP,NEW IP is : $NEW_IP > > [Forgot to say that I switched boot target to text with this command : > > sudo systemctl set-default multi-user.target] > > What I tried right now has been to create a respawn service with systemd. > I created a file in /etc/systemd/system/ i.e. warp.service > > [Unit] > Desription=warp with systemd, respawn > After=pre-network.target > > [Service] > ExecStart=/usr/bin/warp > Restart=always > > [Install] > WantedBy=multi-user.target > > > and I've activated it : > > systemctl enable warp.service > > > rebooted and started it manually : > > systemctl daemon-reload > systemctl start warp.service > > It does not work and anyway it does not seem to be what I want... > > [image: Istantanea_2024-05-12_23-46-37.png] > > I want that the warp script is run everytime root is logged in,not > more,not less. > I suspect that the solution is easier than what I'm trying to do... > > -- > Mario. >