We are thinking of using a batch file as shown below for our software deployment. While we don't need high security we are still wondering if there are obvious security issues with this approach.
@echo off
set /p PASSWORD="Please enter sudo password:"
ssh -t user@host "echo %PASSWORD% | sudo -S su;sudo docker container ls"
We are running the batch file on our dev machines (Windows) to deploy docker containers to Linux machines. While running the file we are prompeted for the sudo password which is then used in the SSH command. The restart of the docker containers and some other commands need to be run as sudo after the deployment. The users on the Linux machines do not have sudo access nor the root password.
If the SSH command is executed like this, is this logged somewhere, e.g. in a SSH command history or the history of the user?
Are there improvements we could make to this approach?
For sure there are more elaborate ways to do this, but for now we need a solution as simple as this which is simple and pragmatic.
ps
). You could circumvent this entire thing either by configuring/etc/sudoers
to allow your docker commands to be run withsudo
without a password (no need forroot
anymore), or setup docker to run as non-root user. – Panki Jan 11 '23 at 17:22