Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This code does not work:

scp ~/Desktop/favicon.ico nameOfBashAlias:/public_html/mySite/templates/blog/

The alias is:

alias nameOfBashAlias='ssh myUsername@11.11.11.111'

How do I solve this problem?

Edit

Is something similar to the following code possible, like running many instances of bash?

scp ~/Desktop/favicon.ico (nameOfBashAlias)>:/public_html/mySite/templates/blog/

I did not get the above code to work.

share|improve this question

migrated from stackoverflow.com Jun 2 '11 at 0:30

This question came from our site for professional and enthusiast programmers.

4 Answers 4

up vote 7 down vote accepted

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:

  1. command-line options
  2. user's configuration file ~/.ssh/config
  3. system-wide configuration file /etc/ssh_config
share|improve this answer
    
Yes, I completely agree with your. I am nowadays using that method too, since it syncs a lot better with other system and other tools. –  Masi Apr 25 '12 at 22:32
    
doesnot work for me on MacOSX –  Jabran Saeed Nov 28 at 6:40

scp doesn't run bash. You would need to run this:

 scp ~/Desktop/favicon.ico 11.11.11.111:/public_html/mySite/templates/blog/

If all you have is the alias and the above code is not possible for you, consider running it like this:

nameOfBashAlias cat /public_html/mySite/templates/blog/ > ~/Desktop/favicon.ico

In this way, you're actually invoking ssh and directing the file content to a file on disk. This can be written the other way for uploads.

share|improve this answer
    
The first command should be scp ~/Desktop/favicon.ico username@11.11.11.111:/public_html/mySite/templates/blog/ –  Masi Mar 9 '09 at 17:35

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.

share|improve this answer
    
@mataap: Thank you very much for your answer! –  Masi Apr 30 '09 at 4:09

No, your examples will not work, because that is not how BASH aliases work. I suggest you use a variable. Put this in your ~/.profile or ~/.bashrc [whichever you use]:
site="user@site.com"
then in your terminal, this will work:
scp favicon.ico $site:/dir/


Or you could write a script like I do for my iPod. in my bashrc I have ipod=192.168.2.60, then in my script I source ~/.bashrc so it gets my variables in the script, then in the script: scp $1 $ipod
the downside is I'd have to edit the script to do recursive. and I can only do 1 file. but when I need either of those I usually use scp directly from the terminal!
~Matt

share|improve this answer

Your Answer

 
discard

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.