SSH client
Copy your key to another host
This is the easiest way to copy your key to another host.
ssh-copy-id username@10.10.10.10
Sample ~/.ssh/config
Here is a sample ~/.ssh/config file that explains and create, design, and evaluate different needs for remote access using ssh client.
# default for all
Host *
ForwardAgent no
ForwardX11 no
ForwardX11Trusted yes
User nixcraft
Port 22
Protocol 2
ServerAliveInterval 60
ServerAliveCountMax 30
# override as per host
Host server1
HostName server1.cyberciti.biz
User nixcraft
Port 4242
IdentityFile /nfs/shared/users/nixcraft/keys/server1/id_rsa
# Home nas server
Host nas01
HostName 192.168.1.100
User root
IdentityFile ~/.ssh/nas01.key
# Login AWS Cloud
Host aws.apache
HostName 1.2.3.4
User wwwdata
IdentityFile ~/.ssh/aws.apache.key
# Login to internal lan server at 192.168.0.251 via our public uk office ssh based gateway using
## $ ssh uk.gw.lan ##
Host uk.gw.lan uk.lan
HostName 192.168.0.251
User nixcraft
ProxyCommand ssh nixcraft@gateway.uk.cyberciti.biz nc %h %p 2> /dev/null
# Our Us Proxy Server
# Forward all local port 3128 traffic to port 3128 on the remote vps1.cyberciti.biz server
# $ ssh -f -N proxyus
Host proxyus
HostName vps1.cyberciti.biz
User breakfree
IdentityFile ~/.ssh/vps1.cyberciti.biz.key
LocalForward 3128 127.0.0.1:3128
Vérifie la longeur des clés
Vérifie la longeur des clés dans le fichier spécifié :
ssh-keygen -l -f ~/.ssh/authorized_keys
Verifying if private and public key natch together
PRIVKEY=id_rsa
PUBKEY=id_rsa.pub
diff <( ssh-keygen -y -e -f "$PRIVKEY" ) <( ssh-keygen -y -e -f "$PUBKEY" )
Show SSH pub key details
ssh-keygen -l -f pubkey.pub
2048 SHA256:REDACTED cptest@domain.tld (RSA)
Sortir d'une connexion SSH gelée
Comment sortir d'une connexion SSH sous linux qui est connectée sur un host qui n'est plus joinable mais que la session (SSH) est comme gelée.
~. - terminate connection (and any multiplexed sessions)
~B - send a BREAK to the remote system
~C - open a command line
~R - Request rekey (SSH protocol 2 only)
~^Z - suspend ssh
~# - list forwarded connections
~& - background ssh (when waiting for connections to terminate)
~? - this message
~~ - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)
SSH key pour GitLab
Sur l'ordi qui va faire un pull, s'assurer que vous n'avez déjà une clé RSA :
cat ~/.ssh/id_rsa.pub
Si elle n'existe pas, générer une nouvelle clé :
ssh-keygen -t rsa -C "votre_email@example.com" -b 4096
Ensuite, coller la clé "publique" dans la section SSH de votre compte sur le serveur GitLab (https://gitlab.example.com/profile/keys).
cat ~/.ssh/id_rsa.pub
Vous pouvez tester le tout avec :
ssh -T git@git01.noamc.com # ou @10.25.25.157
# Vous devriez voir : "Welcome to GitLab, <votre_nom>!"