3

i've been trying to clean up my root directory so that it isn't clustered with random dotfiles. nonetheless, on setting up the ssh-key i came to a dead-end, where i wouldn't find a way to migrate known_hosts file to the other direction ($XDG_CONFIG_HOME/ssh/).

i used this command to generate my ssh-key:

mkdir -p $XDG_CONFIG_HOME/ssh
ssh-keygen -t ed25519 -C "[email protected]" -f $XDG_CONFIG_HOME/ssh/id_ed25519

but yet i need to create a ~/.ssh/config file to point at my $XDG_CONFIG_HOME/ssh/config file, which is frustrating because i want to get rid of the ~/.ssh directory

i used several approaches one of them was to set an env var SSH_CONFIG to $XDG_CONFIG_HOME/ssh/config but that didn't work either

⚠️ i'm using macOS and fish shell to prevent confusion

this is the $XDG_CONFIG_HOME/ssh/ directory structure:

config
id_ed25519
id_ed25519.pub
known_hosts #this file is ignored as ssh expects its in ~/.ssh/

this is the $XDG_CONFIG_HOME/ssh/config file:

GlobalKnownHostsFile $XDG_CONFIG_HOME/ssh/known_hosts #this doesn't help either 
Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile $XDG_CONFIG_HOME/ssh/id_ed25519

and the current fix that is working, is only creating a .ssh/config with the value UserKnownHostsFile $XDG_CONFIG_HOME/ssh/known_hosts, which makes my whole migration of the files pointless.

.ssh/config file:

UserKnownHostsFile $XDG_CONFIG_HOME/ssh/known_hosts

is there something that i'm missing?

how can i fix this?

or is there a better way of organising one selfs root folder?

i tried to set the env var SSH_CONFIG but it seems to ignore it:

set -Ux SSH_CONFIG ~/.config/ssh/config #fish syntax, it's the same as: export SSH_CONFIG="$HOME/.config/ssh/config"

1 Answer 1

2

The post How can you change the default location of the .ssh folder has this answer by Binita Bharati:

To change the default location for the .ssh directory, you can edit the below settings:

  1. /etc/ssh/ssh_config: Edit the value for IdentityFile. A sample entry would look like this: IdentityFile /es2/ssh/id_rsa. Here /es2/ssh is the desired directory to keep the public and private keys.
  2. /etc/ssh/sshd_config: Update the value for AuthorizedKeysFile, A sample entry would look like this: AuthorizedKeysFile /es2/ssh/authorized_keys

Also, do not forget to restart your ssh daemon after making this config updates.

Reference : sshd_config(5).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .