Question: How do I change the route cmder has to find ssh keys?
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
- [X] I have read the documentation and made sure what I'm looking for isn't present, or is unclear.
- [X] I have searched for similar issues, and either this question wasn't asked before, or I didn't find any that describe my question.
By asking Claude 3 (AI) this are the steps.
- Go to Settings...
- Go to Startup -> Tasks
- 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.
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.
Yeah the AI made up a bad answer, LOL.
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.shAdd:
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.dand just drop a*.sh|cmd|ps1file 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
If you edited $CMDER_ROOT/config/user_profile.sh and are using bash::bash then export is indeed a valid command.
apparently i am using cmd::Cmder
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"
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.
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.
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.
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.
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"
[!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.
@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.
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?
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.
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?
Below shows symlinks on Windows:
-
You need to enable
Developer Modein Control Panel or be an administator. -
Add the below to use native windows symlinks using the
lncommand.
-
set MSYS=winsymlinks:nativestictin%cmder_root%\config\user_profile.cmd -
export MSYS=winsymlinks:nativestictin%cmder_root%\config\user_profile.sh -
$env.MSYS=winsymlinks:nativestictin%cmder_root%\config\user_profile.ps1
- Create
%cmder_root%\config\.ssh. - Add your config and keys to the folder.
- Create the symlink:
-
ln -sf %cmder_root%/config/.ssh %userprofile%/.ssh
- try and see if it works.
See below creating the symlink in the Cmder Cmd.exe shell:
Note: I do not know if this will work but the symlink can be created.
sadly I don't have symlink (i am working with windows), i tried with
mklink /D %cmder_root%\config\.ssh %userprofile%\.sshand 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.
essentially this would make the files present in both locations. editing/adding files to one location would edit/add in both locations.
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
It does work, If it works for you:
@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
@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.
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.