0

I have connected one of my production server folders with my "ssh account" server via sshfs.

I often need to find out pwd (or realpath) of the file on the original (production) server, but the pwd returns the path to file on the connected ("ssh account") server.

Is there a way to get original path?

Thanks

Edit: more about this: I am using this to link my ssh server to multiple different SFTP servers/shared hosting.

so, if i do this (on some of the servers): sshfs user@domain:/ mount_point, then I am connected to my FTP account, which acts as root for my user, but is more along something like /var/www/clients/c/a/account/pub/ and that's the path I need –

sshfs user@domain:/ mount_point # mount SFTP acc.
cd mount_point
XXXX file.ext # get back: /var/www/clients/…/pub/file.ext
pwd file.ext # returns /ssh-server/path/mount_point/file.ext

Hope it makes sense now.

Thanks

Adam Kiss
  • 123
  • 7

2 Answers2

1

You can get the path mounted via sshfs from the output of mount (or simply remember it). Then you can either

  • build an alias that takes a path on the client, removes the mountpoint of the SSHfs and prepends the original name of the directory on the server. For example, if you mount the remote directory /var/www/mywebsite locally to /home/test/website (sshfs server:/var/www/mywebsite /home/test/website), then the following will work:

    $ alias mpwd="pwd | sed 's|^/home/test/website|/var/www/mywebsite|'"
    $ pwd
    /home/test/website
    $ mpwd
    /var/www/mywebsite
    $ cd gallery
    $ mpwd
    /var/www/mywebsite/gallery
    $ cd /etc
    $ mpwd
    /etc
    

    Note how non-matching directories (/etc) are not mangled.

  • mount the remove directory at the same location locally, that is, execute sshfs for example like: sshfs server:/var/www/mywebsite /var/www/mywebsite. The directory obviously has to exist locally for that to work.

Claudius
  • 9,558
1

Don't you know the path that is exported/mounted on your local machine? Wouldn't all paths under mount point be relative to the "exported" path?

sshfs [user@]host:[dir] mountpoint [options]

so if you are in [dir]/foo/bar then the pwd on the real host is /[dir]/foo/bar.

If you are mounting you home folder (default if no [dir]), and it is in a "custom" place, then finding out your home path may be done like so:

$ ssh flode echo \$HOME
/home/pvv/d/rakhmato

...then whatever I have at mountpoint/moo/hei is actually in /home/pvv/d/rakhmato/moo/hei

If the [dir] you are mounting is an alias to another folder (mount -o bind), then you can locate the original path by looking at the /etc/mtab file. Something like:

$ ssh localhost mount |grep '/media.*bind'
/mnt/media/media on /media type none (rw,bind)
/mnt/media/root-extension/usr/share/doc on /usr/share/doc type none (rw,bind)

...where localhost is the name of your server and '/media' is the [dir] that you mount via sshfs.