Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I do:

ssh-keygen -N password123\$ -f bobskeys

Is \ escaping the $ character or becoming part of the password?

Or rather, will bash be doing any escaping before ssh-keygen gets the password value?

Do I need to escape the $ character?

I'm running Centos 5.5 x64 and bash 3.2.25

share|improve this question
and now we all know your password... ;-) – Michał Šrajer Dec 20 '11 at 23:01
up vote 4 down vote accepted

When you type:

ssh-keygen -N password123\$ -f bobskeys

the shell will execute ssh-keygen with arguments -N password123$ -f and bobskeys.

If you want to pass password123\$ as an argument you need to single-quote it:

ssh-keygen -N 'password123\$' -f bobskeys

or backslash the backslash:

ssh-keygen -N password123\\$ -f bobskeys

Otherwise the ssh-keygen process will not see the backslash.

share|improve this answer
Thanks for "getting" the question :). – Kev Dec 21 '11 at 11:55

from the ssh-keygen man page:

A passphrase is similar to a password, except it can be a phrase with a series of words, punctuation, numbers, whitespace, or any string of characters you want. Good passphrases are 10-30 characters long, are not simple sentences or otherwise easily guessable (English prose has only 1-2 bits of entropy per character, and provides very bad passphrases), and contain a mix of upper and lowercase letters, numbers, and non-alphanumeric characters.

since the -N argument is to create a new passphrase, the \ sign is part of the paraphrase.

share|improve this answer
So bash won't be doing any escaping before ssh-keygen gets the password value? – Kev Dec 20 '11 at 20:41
Actually, that might depend on the shell. It appears to me that both bash (4.1) and zsh (4.3.11) will change \$ to $ as part of parsing. (At least, echo -E \$ | od -c will show no backslash, where as single-quoting it would.) – Ulrich Schwarz Dec 20 '11 at 20:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.