I have an EC2 instance that's typically used via manually sshing onto the box as ec2-user
. Over time the box has accrued various custom configurations such as docker config and git access to our private repositories.
Am trying to automate some commands on the box using AWS System Manager, but system manager logs in as root
, which lacks the aforementioned configuration of ec2-user
. Is it possible to somehow login as ec2-user
from system manager or change users while logged in? Because the box has been customized over several months, its not obvious how to reconfigure from scratch (also don't have time to dive into).
Have tried changing user via su ec2-user
to no avail.
As a workaround, I'm simply running SSH commands on the box directly eg
ssh -i ~/.ssh/MYPEM.pem [email protected] "touch FOOFILE && git clone REPO"
but this avoids system manager altogether and is undesirable.
Thanks to @jordanm for pointing me in the right direction. I was able to switch to ec2-user afterall using using runuser
command (see more here)
runuser -l ec2-user -c {COMMAND}
for example
runuser -l ec2-user -c 'whoami && git pull'
I guess because AWS System Manger is already root, no additional password/auth requried to switch to ec2-user.