SSH password as a command-line parameter?

Neil Blakey-Milner nbm at
Sun Jun 18 15:18:07 UTC 2006

On Sun 2006-06-18 (16:02), Daniel Carrera wrote:
> I'm working on a remote backup solution for a small website. I want to 
> download a daily copy of a MySQL database. I'd prefer to send it over 
> ssh, so I'm thinking of something like this:
> ssh me at "mysqldump db_name -u me --password=secret | gzip -c" 
> > sql-backup-2006-06-18.gz
> This would work except that I still need to type the ssh password. Is it 
> possible to specify the ssh password in the command line? Or do 
> something else so I can run this on a script?

There isn't (to my knowledge) a way to specify a password, but you _can_
use the "authorized_keys" file to allow something similar and the
opportunity for a lot of further learning.

If you don't already have ssh keys you want to use, you can use
ssh-keygen to generate a pair.  There's the "public" component, which
you can use ssh-copy-id to send to the remote host.  At this point, you
can log into that machine without being asked for a password.

During ssh-keygen, you'll be asked for a passphrase, though.  You can
leave that blank.

It's worth it to put some additional effort in reading the manual pages
on ssh, ssh_config, ssh-keygen, and so forth to fully understand the ssh
environment and the security concerns.

In particular, if you do have a key that doesn't require a passphrase
(because it is going to be used for an automated process), it may be
best to limit that key to only performing a single command.  This can be
done in the authorized_keys file.

Passphrases don't have to be irritating, since Ubuntu graphical logins
run an "agent" (read the ssh-agent manual page) that allows you to
unlock the keys with their passphhhrases for the current session.

Neil Blakey-Milner
nbm at

More information about the ubuntu-users mailing list