Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How do I change the route cmder has to find ssh keys? #2930

Open
2 tasks done
DarioArDi opened this issue Mar 19, 2024 · 25 comments
Open
2 tasks done

Question: How do I change the route cmder has to find ssh keys? #2930

DarioArDi opened this issue Mar 19, 2024 · 25 comments
Labels
👆 Git Upstream issue in Git for Windows. ❔ Type: Question

Comments

@DarioArDi
Copy link

Question

Right now it searches in "~/.ssh "but i would like to put a relative path to not have to copy my keys in the home directory of every computer that I use instead of geting them from the external drive.
I have searched everywhere, I tried looking at user_profile.cmd, start-ssh-agent.cmd and init.bat.

Checklist

  • I have read the documentation and made sure what I'm looking for isn't present, or is unclear.
  • I have searched for similar issues, and either this question wasn't asked before, or I didn't find any that describe my question.
@DarioArDi
Copy link
Author

By asking Claude 3 (AI) this are the steps.

  1. Go to Settings...
  2. Go to Startup -> Tasks
  3. In {bash::bash} (the one that I am using) I added in the commands

set HOME=%CMDER_ROOT%.ssh
set SSH_USER_HOME=%CMDER_ROOT%.ssh

I added a .ssh folder to the cmder root with the keys.

@daxgames
Copy link
Member

daxgames commented Apr 11, 2024

Yeah I would not do it that way.

Cmder has init scripts you can add that stuff to in your case it would be $CMDER_ROOT/config/user_profile.sh

Add:

export SSH_USER_HOME="$CMDER_ROOT/.ssh"

or whatever else you need to configure in your env.

You could also look at $CMDER_ROOT/config/profile.d and just drop a *.sh|cmd|ps1 file to customize bash|cmd|or powershell sessions.

@chrisant996
Copy link
Contributor

Yeah the AI made up a bad answer, LOL.

@DarioArDi
Copy link
Author

Yeah I would not do it that way.

Cmder has init scripts you can add that stuff to in your case it would be $CMDER_ROOT/config/user_profile.sh

Add:

export SSH_USER_HOME="$CMDER_ROOT/.ssh"

or whatever else you need to configure in your env.

You could also look at $CMDER_ROOT/config/profile.d and just drop a *.sh|cmd|ps1 file to customize bash|cmd|or powershell sessions.

It does not recognise export as a command.

Yeah, I did not test it well and in fact, it does not work

@DarioArDi DarioArDi reopened this Apr 11, 2024
@daxgames
Copy link
Member

daxgames commented Apr 11, 2024

If you edited $CMDER_ROOT/config/user_profile.sh and are using bash::bash then export is indeed a valid command.

@DarioArDi
Copy link
Author

apparently i am using cmd::Cmder

@daxgames
Copy link
Member

For cmd::cmder edit %CMDER_ROOT%/config/user_profile.cmd and use set instead of export.

You can also do the same for PowerShell::PowerShell by editing $env:CMDER_ROOT\config\user_profile.ps1.

$env:SSH_USER_HOME = "$env:CMDER_ROOT\.ssh"

@DarioArDi
Copy link
Author

I tried that, and it does not give me an error message, but it wont add the keys. I checked start-ssh-agent.cmd and SSH_USER_HOME does not appear anywhere.
I can't find what to change in there to set the path.

@daxgames
Copy link
Member

I never said what you were trying to do would actually work. I have never even considered moving my ~/.ssh folder as it is against well established convention.

I was just trying to tell you how to properly set env variables for various shells supported by Cmder.

You may have to make a copy of the script you mentioned and edit it to do what you need.

@DarioArDi
Copy link
Author

Ok, I need this to work in orther to have a portable working git with ssh keys so I don't have to copy my keys everywhere.

@DRSDavidSoft
Copy link
Contributor

DRSDavidSoft commented May 7, 2024

Wouldn't using the ssh agent be useful here?

Other than that, maybe editing the ssh\ssh_config file in the vendor\git-for-windows and setting the IdentityFile variables to be a custom path can help you, such as ${CMDER_ROOT}/config/.ssh/... or something like that.

Doing a quick search it seems that %SSH_USER_HOME% is not associated with what you want to do, other people suggest changing the whole %HOME% variable to point to somewhere (like CMDER_ROOT\config) and putting your .ssh folder there.

@DRSDavidSoft DRSDavidSoft added the 👆 Git Upstream issue in Git for Windows. label May 7, 2024
@DarioArDi
Copy link
Author

DarioArDi commented Aug 30, 2024

I was able to make it work, thank you @DRSDavidSoft.

i edited the line in init.bat that defines HOME and that did the trick as you pointed out.

From: if not defined HOME set "HOME=%USERPROFILE%"

To: if not defined HOME set "HOME=%CMDER_ROOT%\config"

@chrisant996
Copy link
Contributor

chrisant996 commented Aug 30, 2024

Caution

The HOME environment variable is used by more than just ssh.

Setting HOME to point into the Cmder config directory will break some other things.

For example, it will make ~ syntax paths point into the Cmder config directory, instead of into the user directory.

So, setting HOME is probably not the best way to resolve the problem.

@DRSDavidSoft
Copy link
Contributor

@chrisant996 Exactly, to my knowledge Windows doesn't provide a way to set the environment variables for a specific task. Best alternative is to alias ssh to a batch script that would temporarily set HOME to the desired path, and revert it back upon ssh exit. I'm not even sure it would always work, might not be reliable at all.

Personally I always make sure that HOME == USERPROFILE.

Msys2 apparently takes care of Windows/Unix path as well.

@DarioArDi
Copy link
Author

well, then there is no easy solution to that? maybe i could set the HOME variable at the start of the ssh agent script and set it back how it was at the end?

@daxgames
Copy link
Member

daxgames commented Aug 30, 2024

Symlink %cmder_root%\config\.ssh to %userprofile%\.ssh and put ssh config and keys in %cmder_root%\config\.ssh

Just a thought. I have not tested it.

@DarioArDi
Copy link
Author

sadly I don't have symlink (i am working with windows), i tried with mklink /D %cmder_root%\config\.ssh %userprofile%\.ssh and it doesn't work either, it says that can't create a file that already exists.
This is the first time that I use this command so i may be using it incorrectly.
Maybe this aproach doesn't work because they would be the "same" folder?

@DarioArDi DarioArDi reopened this Aug 30, 2024
@daxgames
Copy link
Member

daxgames commented Aug 30, 2024

Below shows symlinks on Windows:

image

  1. You need to enable Developer Mode in Control Panel or be an administator.

    image

  2. Add the below to use native windows symlinks using the ln command.

  • set MSYS=winsymlinks:nativestict in %cmder_root%\config\user_profile.cmd
  • export MSYS=winsymlinks:nativestict in %cmder_root%\config\user_profile.sh
  • $env.MSYS=winsymlinks:nativestict in %cmder_root%\config\user_profile.ps1
  1. Create %cmder_root%\config\.ssh.
  2. Add your config and keys to the folder.
  3. Create the symlink:
  • ln -sf %cmder_root%/config/.ssh %userprofile%/.ssh
  1. try and see if it works.

See below creating the symlink in the Cmder Cmd.exe shell:

image

Note: I do not know if this will work but the symlink can be created.

@daxgames
Copy link
Member

sadly I don't have symlink (i am working with windows), i tried with mklink /D %cmder_root%\config\.ssh %userprofile%\.ssh and it doesn't work either, it says that can't create a file that already exists. This is the first time that I use this command so i may be using it incorrectly. Maybe this aproach doesn't work because they would be the "same" folder?

You need to delete the folder before trying to create the symlink.

@daxgames
Copy link
Member

essentially this would make the files present in both locations. editing/adding files to one location would edit/add in both locations.

@DarioArDi
Copy link
Author

That's the thing, my objective is to have cmder in a external drive so i can use it wherever without having to copy my ssh keys in every computer. I did not spect for this to be so conversome haha.
Could i just edit start-ssh-agent.cmd to look where i want instead of HOME? or whichever the script that looks for the keys is

@daxgames
Copy link
Member

daxgames commented Sep 1, 2024

It does work, If it works for you:

image

@daxgames
Copy link
Member

daxgames commented Sep 1, 2024

@DarioArDi The only thing I know of is using a ~/.ssh/config file and use the IdentityFile key to point to where your key is as shown below:

https://stackoverflow.com/questions/84096/setting-the-default-ssh-key-location

@daxgames
Copy link
Member

daxgames commented Sep 1, 2024

@DarioArDi You could also write some code in your %cmder_root%/config/user_profile.* init scripts that automatically copies keys stored in your Cmder folder on USB to %userprofile%\.ssh if they do not exist. So when you start Cmder whatever machine you run it on is automatically configred.

@DarioArDi
Copy link
Author

That would make it work, but again, i don't want to leave copies of my keys everywhere.
Im going to try the IdentityFile and see if i can check the config to change it if it isin't configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👆 Git Upstream issue in Git for Windows. ❔ Type: Question
Projects
None yet
Development

No branches or pull requests

4 participants