Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove directory in a remote machine using shell script

Tags:

shell

ssh

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.

like image 980
Harish Avatar asked Oct 17 '25 12:10

Harish


1 Answers

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

like image 182
sjsam Avatar answered Oct 19 '25 05:10

sjsam