0

I want to execute a command as root user via SSH. I tried supplying the root password using the -p flag, it doesn't work.

> ssh -i ~/.ssh/sshserverprivatekey normaluser@IP sudo -p 'ROOTPASSWORD'
> grep ShardID latest/validator*.log
0

2 Answers 2

2

You need to add your public key to /root/.ssh/authorized_keys and simply SSH in as root and run the command:

ssh root@server whoami

Where whoami could be any command.

1
0

sudo does not support passing the password on the command line, so that is not possible. You can do

ssh [...] sudo [command]

and type your password at the prompt. However, with default SSH settings your password will be displayed on your terminal in clear as you type it. To avoid that, add the -t flag to your ssh command or add RequestTTY yes to your ~/.ssh/config file (create the file if it does not exist yet).

1
  • This is useful. Thanks. Since I have many such commands to execute and don't want to enter the password manually, I prefer the solution suggested by @kristopher-Ives. Thanks again for your reply. Aug 29, 2019 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .