Skip to content

Instantly share code, notes, and snippets.

@RealYukiSan
Last active July 13, 2024 18:59
Show Gist options
  • Save RealYukiSan/8e2a9e3f8c6abbab0ab926c3ecd627dd to your computer and use it in GitHub Desktop.
Save RealYukiSan/8e2a9e3f8c6abbab0ab926c3ecd627dd to your computer and use it in GitHub Desktop.
Git and SSH

Better format

Authenticate #git through #ssh

Generate asymmetric key using the command below:

cd ~/.ssh
ssh-keygen -t rsa

Add the public key as auth key in github account's settings

Add private key to ssh agent:

# first of all, activate ssh agent
eval ssh-agent $SHELL
# add key to agent
cd ~/.ssh
ssh-add ./key
# make sure the key was added
ssh-add -l
Check connectivity with authentication:
ssh -T git@github.com

Verify signature on #git commit by #ssh public key

Add public key as signing key in github account's settings

Update git config:

git config [--global] gpg.format ssh
git config [--global] commit.gpgsign true
git config [--global] tag.gpgsign true
git config [--global] user.signingkey ~/.ssh/key.pub

Check signed commit by:

git commit -am "test signed commit" --allow-empty

Optional, if you encounter an error:

git config --global gpg.program "the/path/to/program"

add ~/.ssh/config to make it automatically connect, see man 5 ssh_config for futher information and see stackoverflow for multiple credential

Example config:

Host reyuki.github.com
	HostName github.com
	IdentityFile ~/.ssh/reyuki

Host myself.github.com
	HostName github.com
	IdentityFile ~/.ssh/myself

Host serper
  HostName 192.168.18.12
  User root
  Port 22
  IdentityFile ~/.ssh/serper

Footnotes:

  • This guide not providing reassign commit that already committed without even verified
  • And also doesn't provide signing in file scope
  • Make sure your remote url using ssh protocol

enable and start sshd (server-side)

systemctl enable sshd --now

you need to configure your /etc/ssh/sshd_config at first time setup.

if the server only have root user, change the PermitRootLogin

after you're able to access your ssh server, I recommended you to change the authentication-way to public key because it's more comfortable :v

here's the "how":

[client-side]

  • generate ssh key: ssh-keygen -t rsa
  • copy pubkey: ssh-copy-id -i your_file.pub username@server

[server-side]

  • enable pubkey auth method: set PubkeyAuthentication to yes
  • disable the password auth method: set PasswordAuthentication to no

you can follow above instruction (revision.md) for the next step (Add private key to ssh agent)

Import my public keys and allow me to communicate with you >///<

@RealYukiSan
Copy link
Author

RealYukiSan commented Jul 13, 2024

for HTTP version, see the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment