What Does –– (double dash) Mean In SSH Shell Command?

Posted on in Categories , , , last updated December 3, 2013

I see lots of seasoned admins and cloud provider wrapper scripts use ssh client command as follows in shell:

ssh [email protected] --

What the double -- (dash) does here? Why it is used in this shell command and why not just use the following?

ssh [email protected]

The double dash “--” means “end of command line flags” i.e. it tells ssh command not to try to parse what comes after command line options. You will see something as follows when you use gcutil ssh vmNameHere python wrapper. It will display and execute ssh as follows:

ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no -i /Users/vivek/.ssh/google_compute_engine -A -p 22 [email protected] --

This syntax ensures that you can run commands on the remote server without ssh parsing them:
ssh [email protected] -- command1 --arg1 --arg2

The above syntax tell ssh not try to parse --arg1 and --arg2 after -- command line options. This ensures that command1 will accept --arg1 and --arg2 as arguments.

## safe examples ##
ssh [email protected] -- --commandName --arg1 --arg2

This kind of behavior is mostly defined and handled by the ssh command and not by your bash/ksh/csh shell. This is also true for many other commands. For example you can not create or view a file named --file or -f using cat command

## fail ##
cat --file
cat -f

Instead try passing double dash “--” to instruct cat command not to try to parse what comes after command line options:

## works ##
cat -- --file
cat -- -f
See also

You may also want to read the following faq:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

3 comment

Leave a Comment