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?

eudoxos
  • 363
  • 2
  • 3
  • 11

3 Answers3

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.

TheCompWiz
  • 7,409
  • 17
  • 23
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).

Scott Keck-Warren
  • 1,670
  • 1
  • 14
  • 23
1

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

myscp() {
  scp ${1%%:*}${SCP_DIR:?/tmp}/${1#*:}
}
Dan Andreatta
  • 5,454
  • 2
  • 24
  • 14