Home » Questions » Computers [ Ask a new question ]

Unable to use scp with a bash alias

Unable to use scp with a bash alias

This code does not work:

Asked by: Guest | Views: 293
Total answers/comments: 2
Guest [Entry]

"I wouldn't recommend using a Bash alias for what you are trying to accomplish. You can just enter all the information into SSH's config file and be done with it. Read the man page for ssh_config if you are curious where these come from. You can do some neat things with ssh_config

The file is located here ~/.ssh/config

Use your favorite editor and create the file and then adjust these to your situation.

Host nameOfBashAlias
HostName 11.11.11.11
User myUsername
Port 22

You are now setup to issue the following command:

$ ssh nameOfBashAlias

Something I bet you didn't know is how integrated this all is. Now that you have this setup, the following commands also work

$ scp /some/file nameOfBashAlias:/path/to/storage/location/

No more remembering that scp uses ""-P"" for port and ssh uses ""-p"". Also this ""alias"" also works in OS X gui apps like Transmit.

OpenSSH obtains configuration data from the following sources in the following order:

command-line options
user's configuration file ~/.ssh/config
system-wide configuration file /etc/ssh_config"
Guest [Entry]

"Aliases are substituted when they are the first word of a bash command. Your alias appears at the start of the third word.

I would use a shell variable for this.

blah='myUsername@11.11.11.111'
scp ~/Desktop/favicon.ico ${blah}:/public_html/mySite/templates/blog/

Btw, I think your original alias shouldn't have ssh in it. And the last code sample has a > in it that looks wrong too."