I have a problem with the PATH variable on Debian Linux when executing commands via SSH. This happens for example when I use GIT or Mercurial and I have them installed in /opt instead of /usr/local. But I can also reproduce this easily like this:
When I login to the server via SSH in a normal way and then do echo $PATH then I get the PATH which I have configured in /etc/profile:
/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/maven/bin:/opt/ant/bin:/opt/mercurial/bin:/opt/git/bin
But when I do ssh user#server 'echo $PATH' instead then I get this:
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
The same happens when I use GIT or Mercurial with an ssh URL. It can't find hg or git executable on the server because it don't get the PATH from /etc/profile.
So the question is: Is there a "more global" way to configure the PATH so it also works with SSH remote execution? Configuring the PATH per user is not an option. Specifying the full path to git/hg executables when using git/hg on the client is also not an option. And I know that I could use symlinks or wrapper scripts in /usr/local/bin to get it working but I'm searching explicitly for a possibility to have a correct PATH when executing commands remotely via SSH.
On Debian, the standard environment is setup through pam_env (in /etc/pam.d/sshd), which will read /etc/environment and /etc/security/pam_env.conf. You can either edit those, or you add another pam_env line to the pam configuration, pointing to an environment file specific to SSH logins.
While not an answer to your problem, from this link, it looks like ssh has a path settings of its own.
The ssh server set some environment variables at the start of the session. You can create a ~/.ssh/environment file on the ssh server to set additional variables (assuming there is a BSD openssh server on the server), but the server must be configured to allow to change the environment.
If the above doesn't work, you can set the remote command. In mercurial this is the --remotecmd switch for push and pull.
I solved this issue by including all necessary files to the .bashrc
For instance:
. /etc/profile.d/rvm.sh
. /etc/profile.d/bash_completion.sh
Related
After installing Gitea from binary, I can only run the Gitea commands from the gitea home dir with eg. ./gitea -v
How do I set a Path so that Terminal responds to Gitea commands? The server is up and running and have created accounts etc.
Does a Path need to be added somehow to the .bashrc file?
The answer should enable "gitea" to be typed in Terminal as a command anywhere not just in the home Gitea folder.
Have you tried to use export in your .bashrc?
export PATH=$PATH:/my/path/to/gitea
By adding $PATH in the export, it appends the path gitea path rather than overwriting the PATH environment variable.
I am running a Windows Powershell provided through the git for windows installation. This shell provides many unix style commands (i.e. "ls", "mv", etc.).
My question is: How do I access Unix style paths from the powershell cmd line on Windows?
Consider this example: the "ls" program is installed and works in the powershell. The path is shown as "/usr/bin/ls" if I type "which ls" as the cmd prompt. But if I try to change my current directory using "cd /usr/bin/", the shell complains that the path is not found.
I can't see any mounted volumes or anything like that using "mount" (perhaps in PowerShell it is a different command?).
I'm asking this question because I have other files that I need to get to which are listed under unix-style paths, and right now I can't get to anything. I figure if I can get to /usr/bin, then I can figure out how to get where I really need to go.
Powershell is not Unix. It may have a few familiar commands like "ls" and "ps", but that's where the similarity ends.
When you installed Git For Windows, you likely installed the Git Bash shell as well. Run that instead to get a more Unix like atmosphere. (Re-install Git For Windows if you didn't select this option on install).
But even with Git Bash, there's still no such folder as /usr/bin. That folder doesn't exist on Windows. If you want a Unix emulation on Windows that includes the traditional folder structure, use Cygwin. And you can run Git on that environment too and access an emulated /usr/bin folder.
If I run a 'git clone' from the Windows 10 command line to a Linux remote repo in our office, there seem to be no permission issues; I'm presented with an ssh login prompt to the remote server, my password is accepted, and the clone runs to completion without a problem.
If I run the same 'git clone' from Cygwin, I don't even get the login prompt and the git command fails with:
Permission denied (publickey,password)
The thing is, I think I know why the problem is happening, but not what to do about it.
Image my name is John Smith. My credentials as stored by the remote Linux server are 'john.smith'. My Windows user folder is 'C:\Users\john.smith'. However, when I start a Cygwin session, the prompt is actually 'John.Smith#myhostname'. So because Windows is case-insensitive, the git clone works because the Windows copy of 'known-hosts' can be located (no case issues). However, the copy of 'known-hosts' in Cygwin isn't being located because of the mismatch between the Unix username (john.smith) and the Cygwin username (John.Smith). That's my theory anyway !
What do I need to do in Cygwin to lower-case my username so that everything aligns ?
Thanks
Can you try to issue the clone command with the format: john.smith#linuxhost:path/to/repo?
Check where your git configuration is
git config --list --show-origin
cygwin probably uses /home/john.smith as home/profile folder(directory).
But here is main issue ssh configuration.
You could copy your ssh private and host keys from windows location to cygwin home .ssh directory.
Check in your Cygwin install folder under <install-path>/Cygwin/home/<username>
You should find:
.gitconfig - edit this to change your username and email address etc...
.ssh - this contains your known-hosts and id_rsa ssh keys. You probably need to copy your windows ones into here.
You may also find other issues in Cygwin like auto complete not working? and a few other gotchas...?
when I make git clone with ssh from a user prompt it works properly.
git clone ssh://URL.com/soft.git soft_git
the ssh key id_rsa and id_rsa.pub are under /home/user/.ssh
my purpose is the execute git with sudo but I got the following error
Cloning into '/home/user/git/soft'...
Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I create a folder /root/.ssh and I copy the ssh keys into it but I got the same error
how to execute git with sudo properly.
When you run git using sudo, git will run as root. Because git is running as root, ssh is running as root. Because ssh is running as root, it is trying to log on to the remote server as root. The remote server is not okay with this (as it should be!)
You will need to do two things:
Put the username in your URL: ssh://myusername#URL.com/soft.git.
Make your SSH key available to the root user, because it will look under /root/.ssh instead of /home/user/.ssh. (You could also probably point SSH at the correct key, but I don't know how to do this, and SSH is picky about permissions.)
On my computer (Ubunutu 18.04), adding SSH_AUTH_SOCK=$SSH_AUTH_SOCK after sudo and before git fixed the problem:
sudo SSH_AUTH_SOCK=$SSH_AUTH_SOCK git clone git#github.com:my-github-account/my-repo.git
Normally, sudo's SSH_AUTH_SOCK environment variable won't be set properly. Executing the git clone with SSH_AUTH_SOCK=$SSH_AUTH_SOCK sets sudo's SSH_AUTH_SOCK environment variable to whatever it is for you.
This way, you don't need to add an extra .ssh dir for sudo with copies of your keys, which is what I think one of the other answers suggests.
The solution is more fully explained in this rather old github gist:
https://gist.github.com/scottjacobsen/4281310
P.S. I'm adding a new answer several years later; I googled a solution to this problem, and this SO Q/A is one of the first things that comes up.
Normally the default remote ssh user is the same as your user name. If you're using sudo this will be root which probably isnt' going to work. You need to supply the remote username.
sudo git clone ssh://username#URL.com/soft.git soft_git
You can generally resolve git ssh issues easier by trying to login to the remote with plain ssh. You'll get better diagnostics and can see what's going wrong.
sudo ssh ssh://URL.com/
SSH in our country is blocked, So I have to use a forked ssh software called obfuscated-openssh , I installed it in /opt directory in linux OS , How can I force git to use /opt/ob-openssh/bin/ssh not /usr/bin/ssh ?
Use the GIT_SSH environment variable to point to your version of ssh.
The easiest way is to set the environment variable GIT_SSH to point at your SSH client.
From the man page:
GIT_SSH
If this environment variable is set then git fetch and git push will use this command instead of ssh when they need to connect to
a remote system. The $GIT_SSH command will be given exactly two
arguments: the username#host (or just host) from the URL and the shell command to execute on that remote system.
To pass options to the program that you want to list in GIT_SSH you will need to wrap the program and options into a shell
script, then set GIT_SSH to refer to the shell script.
Usually it is easier to configure any desired options through your personal .ssh/config file. Please consult your ssh
documentation for further details.