Hi so basicly what I am trying to do is run a script that is located on the remote server as root by running su - before running the script.
I need to run the script after running the command su - otherwise it wont run. And at the state that the server will be sudo isnt installed yet.
Right now I have ssh -t $USERNAME@$IP "su - && /home/$USERNAME/firstboot/firstboot.sh" but it connects me as su - on the remote server but dosnt execute the script.
Any idea would be greatly apreciated thank you.
Fundamentally, you can't use
sulike that. Forgetsshfor a moment; if you runsu - && date, thedatecommand will only execute after thesushell has exited (becausecommand1 && command2means "runcommand1first, and if it exits successfully, runcommand2).You need to use the
-coption tosuif you want to run a command in thesuenvironment:In your script, that means you want to run:
So your ssh command should look like: