(svn+ssh) getting bash to load my PATH over SSH

19,451

Solution 1

You can try launching the command via a bash using the -l command so it acts as a login shell

ssh user@server "bash -l -c 'which svnserve'"

As noted in comments I left above, you'll need to escape all $ so variables get expanded on the server and not locally. E.g.:

ssh user@server "bash -l -c 'echo \$PATH'"

update:

Regarding you question on why .ssh/environment does not take effect, I believe the default config for SSHd would be to ignore user environments. You need to specifically enable it in /etc/ssh/sshd_config (or similar) and add:

PermitUserEnvironment yes

update 2:

If you do not have access to /etc/ssh/sshd_config, a possible (but not ideal) solution would be to use public-key authentication to launch svnserve on login.

See http://svnbook.red-bean.com/en/1.4/svn.serverconfig.svnserve.html#svn.serverconfig.svnserve.sshtricks

Note that this will affect your ability to log in normally via SSH. To do so, you need to bypass the public key authentication:

svn -o PubkeyAuthentication=no user@server

Solution 2

As it happens, .bashrc and .bash_profile are only executed if you're in an interactive shell. When you login through ssh, you are not in an interactive shell, therefore your custom PATH definitions are never run. You can associate a script to non-interactive sheels using BASH_ENV. Check also .ssh/environment which gives you another alternative. The best way to know about this is by doing man ssh.

Good luck!

Solution 3

I have the same issue with HostMonster, due to a recent change they made. I found a workraound in an old email thread at http://svn.haxx.se/dev/archive-2007-02/0204.shtml:

On your workstation:

  • edit ~/.subversion/config: locate [tunnels] and add the line ssh=~/svnssh
  • create ~/svnssh as in the link:

    #!/bin/sh
    /usr/bin/ssh $1 /<ur_bluhost_home_path>/sshsvnserve -t

  • chmod +x ~/svnssh

On your bleuhost account:

  • create ~/sshsvnserve, same content as the link:

    #!/bin/sh
    /<ur_bluehost_home_path>/bin/svnserve $*

  • chmod +x ~/sshsvnserve

That's it. The config [tunnels] change modifies the command run by svn when handling the svn+ssh namespace and use ur ~/svnssh script instead. The script invokes ssh and passes in the full path to sshsvnserve on ur bluehost account. And sshsvnserve redirects everything to the full path of svnserve, as u install it. Worked for me, no $PATH required.

Solution 4

You can execute an env command:

ssh servername "env PATH=$REMOTEPATH which svnserve"
Share:
19,451

Related videos on Youtube

Eli Bendersky
Author by

Eli Bendersky

Blog Github

Updated on September 17, 2022

Comments

  • Eli Bendersky
    Eli Bendersky over 1 year

    This problem comes up with me trying to make svnserve (Subversion server) available on a server through SSH. I compiled SVN and installed it in $HOME/bin. Local access to it (not through SSH) works fine.

    Connections to svn+ssh fail due to:

    bash: svnserve: command not found
    

    Debugging this, I've found that:

    ssh user@server "which svnserve"
    

    says:

    which: no svnserve in (/usr/bin:/bin)
    

    This is strange, because I've updated the path to $HOME/bin in my .bashrc, and also added it in ~/.ssh/environment. However, it seems like the SSH doesn't read it. Although when I run:

    ssh user@server "echo $PATH"
    

    It does print my updated path!

    What's going on here? How can I make SSH find my svnserve? Thanks in advance

    • Shawn Chin
      Shawn Chin about 14 years
      When you run 'ssh user@server "echo $PATH"', $PATH gets expanded locally so what you get is PATH on localhost. Try escaping $ like so "echo \$PATH". (doesn't solve your problem, but will help with troubleshooting).
    • Eli Bendersky
      Eli Bendersky about 14 years
      @lsc: this explains the "echo $PATH" mystery, thanks
    • Shawn Chin
      Shawn Chin about 14 years
      BTW, you may want to update the title to reflect your actual problem (i.e. svn+ssh). That should help you get more relevant answers.
  • Eli Bendersky
    Eli Bendersky about 14 years
    Sorry, but I noted that .ssh/environment didn't work for me. Any tips of what to write there? Also, I was under the impression that .bashrc is included in non-interactive shells. Otherwise, how is my PATH given correctly via ssh? (echo $PATH)?
  • Eli Bendersky
    Eli Bendersky about 14 years
    Thanks, this makes sense. Unfortunately it still doesn't resolve my original problem which is running svnserve via SSH. for some reason ssh ignores my .ssh/environemnt file and every other attempt I try
  • Eli Bendersky
    Eli Bendersky about 14 years
    after adding a semicolon before which, it says: which: no svnserve in (/usr/bin:/bin)
  • Eli Bendersky
    Eli Bendersky about 14 years
    @Dennis, yes, this is as I would expect. However, in my case I clearly see that .bashrc is NOT being loaded. Moreover, ~/.ssh/environment is ignored. I can conclude that Bluehost (my server provider) configured it this way, which is very unfortunate. P.S. the line with BASH_ENV doesn't work for me
  • Shawn Chin
    Shawn Chin about 14 years
    Oopps.. just notices that @Dennis has already pointed you that way. Apologies for the repetition.
  • Eli Bendersky
    Eli Bendersky about 14 years
    Thanks. Unfortunately since this is a shared server I have no access to /etc/ssh/sshd_config. But from tests I ran it appears this variable indeed isn't set, because ssh ignores my environment file for sure
  • Charles Stewart
    Charles Stewart about 14 years
    @Eli: no semicolon - which is an argument to env