5

The scp (openssh) command accepts relative paths as host:path/ which are relative to the home directory on the host. I would like to change location of the default directory.

For example, I would like to create a shortcut pseudo-host in .ssh/config along the lines of

Host bar
   hostName foo
   ## this directive does not actually exist:
   DefaultDirectory /home/me/some/path/here  

so that I could write

scp some_file bar:baz

instead of

scp some_file foo:some/path/here/baz

Is it possible with openssh?

3 Answers 3

1

The "home" directory is defined by the users' home directory defined in the /etc/passwd file. I don't believe any opensshd parameter will override this behavior. You can change the home-dir of the user... but I don't think this is what you're looking for.

1
  • Eh I know of course where is $HOME defined. And you're right, this is not what I want.
    – eudoxos
    Jan 9, 2012 at 14:48
1

The quick fix for this is to create a symbolic link in your own home directory on the remote server to the directory that you want to access:

ln -s /your/long/path/here/to/webapp1 ~/webapp1

That would allow you to quickly access the folder like so:

scp file foo:webapp1/

and allow for expansion in the future (more than one remote folder) and it won't break other programs. I've found this to be helpful on my servers when I have several websites running on the same server and I need to push files to them (I mostly use git for this now).

1

Another options is of course a small script/function along the lines of (assuming bash here):

myscp() {
  scp ${1%%:*}${SCP_DIR:?/tmp}/${1#*:}
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .