Unable to use scp with a bash alias

This code does not work:

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

The alias is:

alias nameOfBashAlias='ssh [email protected]' 

How do I solve this problem?


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.


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
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

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

 scp ~/Desktop/favicon.ico

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.

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='[email protected]'
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.

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="[email protected]"
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=, 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!

Category: scp Time: 2009-03-09 Views: 1
Tags: scp bash alias

Related post

  • How do I use SCP with two different ports on each IP in script bash 2016-06-27

    How do I use scp with two different ports on each IP. SSH LOCAL : IP= & port=22 I have a redirection ports on a router EXAMPLE SCRIPT BASH: for i in "${array[@]}" array[1]= array[2]=" -p 24&quo

  • Unable to use utf8 with the LyX ClassicThesis version 4.1 2015-02-10

    This is a question about using UTF-8 symbols (e.g. å, Ä, Ö) in the LyX version of ClassicThesis. Using such symbols in the main document lyx files work without any changes at all to the ClassicThesis settings. However, in my use case, I also need my

  • error when using commandline as a bash alias on linux 2009-09-26

    I want to save the following commandline sequence as a bash alias: grep `date '+%d/%b/%Y'` access.logs | egrep 2765330645ae47d292c9ceac725d744e.py |awk '{print $1, $4, $5, $7, $8, $9, $10}' | sort |uniq -c -w15 |sort -n It works fine form the command

  • How to use scp in a bash script without specifying password? 2010-07-30

    I am a bash newbie, and am writing a bash script that will allow transfer of files between two computers. BTW, is there a more secure alternative to scp? Currently, I am doing this manually, by using scp. The remote server always prompts me for the p

  • Unable to use scp on Solaris 2012-02-05

    I'm trying to use scp from one Solaris machine to another, but I get this message and the copy fails: [email protected] # scp -r emcgrab_SunOS_v4.4.4a.tar Password: Sourcing /root/.profile-EIS..... [email protected] What does this mean? How d

  • Unable to use pidgin with proxy 2015-03-17

    I am unable to use Pidgin through my institute network which has proxy(for my yahoo account). The solution suggested in this link does not work with me. I did a lot of googling ,yet I couldn't find a good solution. Is it possible to use Pidgin with p

  • Lubuntu 15.04 : Unable to use wifi with Compaq 6720s 2011-08-04

    I'm having serious problems installing the Broadcom drivers for Ubuntu. It worked perfectly on my previous version, but now, it is impossible. What are the steps to install Broadcom wireless drivers for a BCM43xx card? I'm a user with no advance know

  • Transferring large files using scp with CPU and memory considerations 2010-10-05

    I want to transfer an arbitrarily large file (say >20GB) between 2 servers. I have several considerations: Must use port 22 (ssh) because of firewall restrictions Cannot tax the CPU (production server) Memory efficiency Would prefer a checksum check

  • How to transfer a file from a remote linux machine using SCP with Mingw on Windows7 2013-09-27

    If I am logged into a linux machine via SSH in a mingw window in windows 7; How do I transfer a file to my local machine? I am imagining something like: scp <filename> address_of_local_machine/mydirectory However I don't know how to get the address_

  • Unable to use files with special characters in shell 2014-05-08

    I want to loop through a directory and for every file that is not a directory, i want to append the names together and separate them by comma. files="" for f in $(ls ~/Downloads | grep -v ^d) do files+="$f""," done echo "

  • Unable to use ICD3 with CCS C Compiler 2015-03-24

    I have recently bought ICD3 since I think that being able to debug a microcontroller program requires that we be able to see what is happening inside it. I really want to learn this stuff :) I have a version 5 CCS C Compiler. I used this compiler bef

  • Cant use scp with wdmycloud 2015-07-18

    I can successfully log in to mycloud as root or another user I added. I need to use the scp command to send an image to my folder. It keeps asking for the password and saying its wrong when I know it's right. [email protected] is my local computer but

  • Unable to use multiline with pattern 2013-04-30

    I'm trying to match a string with Pattern/Matcher, however it is failing because I cannot set Pattern.MULTILINE like the Java documentation uses. String testString = 'Line 1: Does not match\nCustomer Name: Bob Dole'; String regex = '^\\s*Customer Nam

  • unabled to use gnucash with mysql 2014-08-30

    I use GNUCASH on windows, and this got the possibility to use mysql. Can I use GNUCASH on ubuntu with mysql connection, because I don't have that option now on ubuntu. And I like ubuntu very much I use ubuntu 14.04 and GNUCASH 1:2.6.1-2 -------------

  • Unable to use paths with spaces in FFMPEG, Android 2015-11-06

    I'm using ffmpeg command line in Android. When I use the command ffmpeg -i /sdcard/d 1.jpg, it says /sdcard/d: No such file or directory. I tried /sdcard/d\ 1.jpg which showed error as /sdcard/d\: No such file or directory /sdcard/d'\' 1.jpg shows er

  • unable to use getElementsByTagNameNS with a JavaScript SOAP 1.2 call to lists.asmx 2016-01-12

    For reasons I do not understand, even though the call is successful and I get data back, I cannot retrieve nodes using getElementsByTagNameNS on xhr.responseXML when using SOAP 1.2 calls. Hopefully my code below can help explain the issue: var SITE_U

  • Unable to use JMockit with OpenJDK 1.7 2016-02-11

    While trying to use JMockit (1.21) with JUnit (4.8) test cases I ran into issue with OpenJDK (1.7). I'm using Eclipse. After searching on SO, I found the solution about adding '-javaagent:path/to/JMockit/jar' argument to JVM and putting JMockit depen

  • Unable to use transitions with TikZ-UML 2011-10-24

    I have a question concerning this minimal example: \documentclass{minimal} \usepackage{tikz} \usetikzlibrary{petri} \begin{document} \begin{tikzpicture} \node[place, tokens=2] (p) {}; \end{tikzpicture} \end{document} This gives me the following two e

  • Unable to use Exim with Exchange/Office 365 - Smart Host 2015-12-07

    I have been struggling with getting Exim and Office 365 to play nice together and am hoping for some insight. Here's my setup: All mail for domain.com gets sent to my Office 365 Exchange server, it attempts to deliver all mail to the appropriate user

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.283 (s). 13 q(s)