Harish Harish - 4 months ago 9
Bash Question

Remove directory in a remote machine using shell script

I'm using Mac machine and I need to connect to remote machine(Linux) and remove the contents of a directory in the remote machine. Tried using

ssh root@server-address rm -rf testdir


It prompts me for the password in the terminal. Is there any way through which I can delete the contents of directory without having to manually enter the password for the remote machine? I want to do this using shell script. As I'm new to shell, any help would be appreciated.

Answer
ssh root@server-address "rm -rf testdir" #suggest you quote the command

looks fine.

You can work-around the password prompt by the steps mentioned [ here ].