We run an application which creates a lot of directories. Once the application completes we do not need those directories. Hence we want to delete them as they are consuming lots of space. The problem is this application is running on a remote server. I have to write a shell script that will delete those directories from the remote server.

I tried the ssh command

ssh [email protected] 'rm /some/where/some_file.war' 

but it asked for a password. Then I followed the below step

Setup password-less keys then add the command as part of the ssh command. See: http://www.dotkam.com/2009/03/10/run-commands-remotely-via-ssh-with-no-password/

I am able to to do all steps as described but at last it is again asking for a password.

How can I use ssh without a password?

  • I'm not able to see the link you posted. Did you use a passphrase when you created the Key? It seems it fails connecting to SSH Server and, at least, use the password machanism to authenticate. Try to repeat connection using ssh -vvv -i <key> [email protected].
    – Echoes_86
    Commented Oct 5, 2016 at 8:54
  • I am wondering if you couldn't just set up a cron job on the remote server to take care of that ?
    – Kate
    Commented Oct 5, 2016 at 11:53

1 Answer 1


Use ssh with public-key authentication. For this you need to generate a key pair using ssh-keygen and copy the public key to the remote system. Specifically, for username append the content of id_rsa.pub (for instance) on your local PC to ~username/.ssh/authorized_keys on the remote system.

If you don't want to enter a password at all, then don't password-protect the private key, e.g. by using the option -N (for openssh) during key generation as in

ssh-keygen -N '' ...

However, no password protection has obvious security implications; specifically, you must protect the private key in other ways. (In such a setting it is probably a good idea to use a dedicated key pair just for the purpose of the given task while restricting what username can do via ssh.)

If you use openssh and if you are willing to enter a password once, then using a ssh agent is another option.

You must log in to answer this question.

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