SSH from /etc/ssh to ~/ssh

How can I change the SSH key use from /etc/ssh/ to ~/.ssh/id_rsa
At the moment when I run ssh -T git@github.com -A -p 22
it finds the key in /etc/ssh/ssh_host_ed25519_key

I also did assign another port on sshd_config and ssh_config from 22 to something else.
In systemctl status the new Port is confirmed after restart sshd but ssh is still running on Port 22 at the moment.

I’m thankful for any help

my ssh_config is:


# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Port 1234
# Port 443
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

StreamLocalBindUnlink yes

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin no
PermitRootLogin prohibit-password
#StrictModes yes
MaxAuthTries 5
MaxSessions 10
PermitRootLogin forced-commands-only

PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
# PermitEmptyPasswords no
PubkeyAcceptedAlgorithms=+ssh-rsa
AuthenticationMethods publickey keyboard-interactive:pam

# HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub

# Change to no to disable s/key passwords
KbdInteractiveAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes

AllowAgentForwarding yes
AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
#PermitTTY yes
PrintMotd no # pam does that
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem sftp /usr/lib/ssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	PermitTTY no
#	ForceCommand cvs server

cat /etc/ssh/ssh_config

#	$OpenBSD: ssh_config,v 1.35 2020/07/17 03:43:42 dtucker Exp $

# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
#  1. command line options
#  2. user-specific file
#  3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

Port 1234
Host *
ForwardAgent yes
ForwardX11 yes
PasswordAuthentication no
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
 #IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
# Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr

#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h
UserKnownHostsFile ~/.ssh/known_hosts.d/%k

also I have this in my .zshrc in I’m not really sure if this is so all fine


# GPG
SSH_AGENT_PID=""
SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/gnupg/S.gpg-agent.ssh"
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
    export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
# Start ssh-agent if not already running
if ! pgrep -u "$USER" ssh-agent >/dev/null; then
    ssh-agent -t 1h >"$XDG_RUNTIME_DIR/ssh-agent.env"
fi

# Source ssh-agent environment variables
if [[ ! -f "$SSH_AUTH_SOCK" ]]; then
    source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
fi
if [[ ! -n ${SSH_CONNECTION} ]]; then
    export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
fi
# Start ssh-agent and redirect output to /dev/null
eval "$(ssh-agent -s)" >/dev/null 2>&1
#
# keychain
keychain -q --absolute --dir "$XDG_RUNTIME_DIR"/keychain
# eval "$(keychain --eval -q gpg ssh id_rsa)"
# eval "$(keychain --eval -q --agents ssh id_rsa)"

ssh_check_agent() {
    ssh-agent
    ssh -V
}

And I play around with vscodium ~/.ssh/config at the moment I commented all out

# Host *
# Host github.com
# Hostname github.com
# User terashy88
# Port 22
# IdentitiesOnly yes
# PubkeyAcceptedKeyTypes +ssh-rsa
# PreferredAuthentications publickey
# AddKeysToAgent yes
# ForwardAgent yes
# IdentityFile /etc/ssh/ssh_host_ed25519_key
# IdentityFile ~/.ssh/id_rsa

# # Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
# # ControlMaster auto
# # ControlPersist yes
# #ControlPath ~/.ssh/sockets/socket-%r@%h:%p
# # RemoteForward remote_agent_socket local_agent_extra_socket
# # RemoteForward remote_agent_ssh_socket local_agent_ssh_socket

#  Host gitlab.com
#     Hostname altssh.gitlab.com
#     User terashy
#     IdentitiesOnly yes
#     Port 1234
#     AddKeysToAgent yes
#     ForwardAgent yes
#     PubkeyAcceptedKeyTypes +ssh-rsa
#     PreferredAuthentications publickey
#     IdentityFile ~/.ssh/id_rsa
# # Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
# # ControlMaster auto
# # ControlPersist yes
# #ControlPath ~/.ssh/sockets/socket-%r@%h:%p
# #     RemoteForward remote_agent_socket local_agent_extra_socket
# # RemoteForward remote_agent_ssh_socket local_agent_ssh_socket
# ssh terashy88@github.com -i ~/.ssh/id_rsa -p 22

# Host github.com
# HostName github.com
# User terashy88
# IdentityFile ~/.ssh/id_rsa.pub
# Port 22

sshd_config is if you are running the SSH daemon on your local machine, meaning you actually want access to your local machine. Judging from your command to connect to github, I doubt, this is what you want.

You should only need to edit the file ~/.ssh/config.

Please revert any changes you did in /etc and test again.

Instead of trying you own agent setup, I recommend using the gnome-keyring for your keys.

2 Likes

Thanks so far, should I really change from Keychain to Gnome keyring on Xfce?

So I revert ssh_config and sshd_config to the standard

and having still the problem that the fingerprint is pointed to /etc/ssh/ED25519

And not ~/.ssh/is_rsa.pub.

With vs code doc, I try to set up the .gitconfig in my .zshrc like this


# todo https://code.visualstudio.com/docs/remote/troubleshooting#_improving-your-security-with-a-dedicated-key

export USER_AT_HOST="$mail_"

export PUBKEYPATH="$HOME/.ssh/id_rsa.pub"

ssh-copy-id -i "$PUBKEYPATH" "$USER_AT_HOST"

git config --global url."git@github.com:".insteadOf "https://github.com/"

git config --global url.ssh://git@github.com/.insteadOf https://github.com/

git config --global user.name "$ngh_"

# git config --global user.email "$mail_"

git config --global url."git@gitlab.com:".insteadOf "https://gitlab.com/"

git config --global url.ssh://git@gitlab.com/.insteadOf https://gitlab.com/

git config --global credential.helper store

git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes"

export GPG_TTY=$(tty)

I set the id_rsa.pub key on GitHub

but I still got this error message


/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/$USER/.ssh/id_rsa.pub"

The authenticity of host 'github.com (140.82.121.3)' can't be established.

ED25519 key fingerprint is SHA256:...

This key is not known by any other names.

Are you sure you want to continue connecting (yes/no/[fingerprint])? ^C/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: Zeile 183: /home/$USER/.ssh/ssh-copy-id.nOBUAkTntH/popids_tmp_id: Datei oder Verzeichnis nicht gefunden

cat: /home/$USER/.ssh/ssh-copy-id.nOBUAkTntH/popids_tmp_id: Datei oder Verzeichnis nicht gefunden

/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.

(if you think this is a mistake, you may want to use -f option)

I trying to fetch my repo and get this error on vscodium


ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory

Host key verification failed.

Schwerwiegend: Konnte nicht vom Remote-Repository lesen.

Bitte stellen Sie sicher, dass die korrekten Zugriffsberechtigungen bestehen

und das Repository existiert.

Fehler: konnte gl nicht anfordern

Von github.com:terashy88/bin

* [neuer Branch] master -> gh_ssh/master

Fordere an von origin

Fordere an von gl

Fordere an von gh_ssh

then I fetch in the terminal, It asks me for the fingerprint of /etc/ssh/ED25519.pub

I did know accept it …it works now, also on vscodium, but I’m kinda confuse does the fingerprint have to run over

/etc/ssh/ED25519.pub

To run my key on GitHub. The key I have on GitHub is the ~/ssh/is_rsa.pub key

You really need to read on the man ssh and go slowly (also github related help).

It’s id_rsa normally, the default file.

It might be going to /etc/ssh/ED25519.pub because it’s looking for a ED25519 type of key (which is recommended, shorter, stronger).

That’s how I normally do it.

ssh-keygen -t ed25519 -C "mygithub"  

use defaults and id_ed25519 files are in your ~/.ssh.

  1. copy contents of your ~/.ssh/id_ed25519.pub to your github account (new SSH key)

git clone git@github.com:repo/repo.git  # use ssh link to your repo

that’s it