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.

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

share|improve this question
1  
What do you get from readlink -f <file> ? –  Xyon Nov 14 '12 at 12:12
    
/ssh-account/path/to/file… the wrong one –  Adam Kiss Nov 14 '12 at 13:08
2  
If your sshd on the server is run in a chroot such that its / is not the actual / on the server and you want that actual /, there is no way to get the actual / on the server via ssh. You could, however, still define an alias as suggested in my answer and simply replace the /var/www/mywebsite accordingly (for example, use /var/www/clients/c/a/account/pub or so). In order not to define multiple aliases, you could parse the output of mount, decide where this actually points to using the username given to sshfs and then build the output accordingly. –  Claudius Nov 14 '12 at 13:20
    
@Claudius wow, I hoped there is something like pwd --see-through-every-mount-and-symlink :D –  Adam Kiss Nov 14 '12 at 13:22
1  
pwd --blatantly-defy-chroot --ignore-filesystem-restrictions --find-absolutely-the-absolute --accept-no-substitutes --never-surrender ? –  Xyon Nov 15 '12 at 7:17

2 Answers 2

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.

share|improve this answer
    
Thanks! This unfortunately won't work for me (I'm connecting to multiple servers… read more about my situation in the edited OP) –  Adam Kiss Nov 14 '12 at 13:13

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.

share|improve this answer
    
I don't have ssh access to [some] of the production servers, and some are just a shared hosting, actually (and I'm using SFTP to connect to them). I'll probably just write to support. Thank you though :) –  Adam Kiss Nov 14 '12 at 13:21

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.