I would like my script to connect to ssh with password, and once connected it will switch to sudo -s and run the mkdir command

for the moment I manage to connect to ssh without entering the password but I cannot do it user switch to create my folder

Look's like:

root@computer:/home/user/test# sshpass -p 'password' ssh admin@  mkdir /var/volatile/flash-upgrade

mkdir: can't create directory '/var/volatile/flash-upgrade': Permission denied

only root user can create folder

  • 1) sudo command is missing after ssh 2) is it always same host and `mkdir' (with random dir ? random hosts ? ramdom users (not always admin) ? – Archemar Feb 5 at 11:28
  • Can you ssh as the user who has the permission to write the command? Can you set up the remote host to allow admin to run sudo mkdir /var/volatile/flash-upgrade without a password (do you own the remote system and can you edit its /etc/sudoers file)? How important is security? Is having plaintext passwords in the shell's history a problem or are you the only user of the system? – terdon Feb 5 at 11:30

Either your admin user on needs to be able to sudo to the correct user, for example ssh sudo id or you could set-up ssh-ing to a user that is allowed root access to the machine, so ssh root@

If you're alone on your home network, both should be OK; in a corporate environment, you should look at the security implications.


you can allow root access only with tagged ssh public key aithentication : in /etc/ssh/sshd_config, set PermitRootLogin forced-command-only Force-command is a command you tag public key in /root/.ssh/authorized_keys such as command="script_you_have_strictly_controlled" id-rsa <public key here> This way you have a controlled elevation to do only authorized and predefined tasks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.