I'm new to linux/bash, and spent many weeks trying to solve how to enable a virtual appliance (linux/bash based) to automatically authenticate and execute a command on a network target.
I got it to work, but am new to linux and dont understand the security implications of what I wrote. Its a homelab, but I would like it to mimic good principles of device security.
My script is stored in /home/userX/bin/ as 'scriptX' and contains the following:
#! /bin/bash source $HOME/.bashrc source *commands to authenticate to target* source *command to scan adapters*
This works when I'm logged into SSH and do ./ to run in an interactive environment. However, as a cron job, it wouldn't work until I sourced $HOME among some other things. I have a cron job setup like the following:
sudo crontab -e
Then inside the cron job
@reboot . /etc/skel/.bashrc ; bash -l -c '/home/UserX/bin/scriptX'
So it works as intended, but I mishmashed parts of scripts I found online until it worked.
Besides changing the account from root to a less privileged user, is there anything I could improve upon with how this operation is handeled?