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
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.
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).