✏️ Made further notation on ssh basics
This commit is contained in:
parent
90c30841b6
commit
175e736802
3 changed files with 236 additions and 52 deletions
|
|
@ -1,60 +1,26 @@
|
|||
OpenSSH, or more commonly known simply as SSH, is a simple Secure Shell protocol that allows us to securely create passwords
|
||||
that are associated with "keys" that will give us a long hashed key that is saved on whatever computer or API we are trying
|
||||
to gain access to in which we can simply apply a password that is associated with that key. The key's hashed values are saved
|
||||
on both our local computer as well as the API, but the passphrase to gain access is stored nowhere (unless we idiotically save it
|
||||
in plain text somewhere, the following is a simle way to set it up on github and use it:
|
||||
Due to there being a lot to cover with ssh, I thought I might further expand upon the subject with links to certain articles for future reference.
|
||||
|
||||
# Generating the SSH key
|
||||
The ~/.ssh directory has many features I was not aware of when first learning about ssh. This includes such things as its own config file (which contains a list of all hosts and which keys they should point to). An example one looks like this:
|
||||
|
||||
# First see what keys are availabe:
|
||||
Host gitlab.com
|
||||
Hostname gitlab.com
|
||||
User z3rOR0ne
|
||||
IdentityFile ~/.ssh/privatekey1
|
||||
IdentitiesOnly yes
|
||||
Host github.com
|
||||
Hostname github.com
|
||||
User tomit4
|
||||
IdentityFile ~/.ssh/privatekey2
|
||||
IdentitiesOnly yes
|
||||
|
||||
ls -la ~/.ssh
|
||||
As you can see, this will point to different privatekeys that can be used with either github or gitlab respectively.
|
||||
|
||||
# To Generate a new SSH key:
|
||||
As you are already aware from the ssh_basics_gh.txt instructions. You can generate a basic ssh key like so:
|
||||
|
||||
ssh-keygen -t ed25519 -C "your_email@example.com" (note that the ed25519 is a key type and is necessary for security reasons,
|
||||
you'll always want to use this type, but keep in mind that you'll probably want to rename this when prompted below so you can make
|
||||
multiple ed25519 keys)
|
||||
ssh-keygen -t ed25519 -C "your_comment"
|
||||
|
||||
# You will be prompted to enter a file to which to save the key into, if you don't specify it will name it the ed25519 field
|
||||
This will start the key generation process including a prompt for a password if necessary (highly recommended, although admittedly when used with git it can get annoying if multiple repositories are being pushed to)
|
||||
|
||||
# You will also be prompted to enter/repeat a passphrase (remember this)
|
||||
So far in my learning journey, I have only utilized ssh as a way of securely accessing my various git repositories, but it's major use is to remotely log into servers. I have provided you (oh future self), with a curled file called ssh_linode.html, which should hopefully give you an idea of how to get started with this (link also below).
|
||||
|
||||
# Then add the SSH key to the ssh-agent
|
||||
|
||||
# First start the ssh-agent in the background.
|
||||
|
||||
evail "$(ssh-agent -s)"
|
||||
|
||||
# It will then list you the Agent pid number (note that yes, this is a process now running the background, this is how
|
||||
it always will authenticate on your end, it is NECESSARY)
|
||||
|
||||
# Then we add the SSH private key to the ssh-agent.
|
||||
|
||||
ssh-add ~/.ssh/ed25519
|
||||
|
||||
# Then from the Github website on your profile page, go to settings and under SSH/GPG keys, add the SSH key including the SHA256 text,
|
||||
but not your email
|
||||
|
||||
#After you have successfully done so (you should see a client side different SSH key that it is associated with), you'll need to test
|
||||
your SSH connection:
|
||||
|
||||
ssh -T git@github.com
|
||||
|
||||
# You should then be prompted with a message like so:
|
||||
|
||||
> Hi username! You've successfully authenticated, but GitHub does not
|
||||
> provide shell access.
|
||||
|
||||
# You're now ready to go, just make sure to specify the origin as origin-ssh instead of origin when pushing to github:
|
||||
|
||||
git add <file(s)>
|
||||
git commit -m "commit message"
|
||||
git push origin-ssh main
|
||||
|
||||
It will then prompt you for your ssh passphrase, enter it and you've successfully committed to github using ssh!
|
||||
|
||||
If you would like to automate it so it doesn't ask for the passphrase (just don't forget your passphrase in case), you can set up
|
||||
automating putting in your passphrase like so:
|
||||
|
||||
ssh-add ~/.ssh/id_ed25519 &>/dev/null
|
||||
https://www.linode.com/docs/guides/use-public-key-authentication-with-ssh/
|
||||
|
|
|
|||
60
ssh_basics_gh.txt
Normal file
60
ssh_basics_gh.txt
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
OpenSSH, or more commonly known simply as SSH, is a simple Secure Shell protocol that allows us to securely create passwords
|
||||
that are associated with "keys" that will give us a long hashed key that is saved on whatever computer or API we are trying
|
||||
to gain access to in which we can simply apply a password that is associated with that key. The key's hashed values are saved
|
||||
on both our local computer as well as the API, but the passphrase to gain access is stored nowhere (unless we idiotically save it
|
||||
in plain text somewhere, the following is a simle way to set it up on github and use it:
|
||||
|
||||
# Generating the SSH key
|
||||
|
||||
# First see what keys are availabe:
|
||||
|
||||
ls -la ~/.ssh
|
||||
|
||||
# To Generate a new SSH key:
|
||||
|
||||
ssh-keygen -t ed25519 -C "your_email@example.com" (note that the ed25519 is a key type and is necessary for security reasons,
|
||||
you'll always want to use this type, but keep in mind that you'll probably want to rename this when prompted below so you can make
|
||||
multiple ed25519 keys)
|
||||
|
||||
# You will be prompted to enter a file to which to save the key into, if you don't specify it will name it the ed25519 field
|
||||
|
||||
# You will also be prompted to enter/repeat a passphrase (remember this)
|
||||
|
||||
# Then add the SSH key to the ssh-agent
|
||||
|
||||
# First start the ssh-agent in the background.
|
||||
|
||||
evail "$(ssh-agent -s)"
|
||||
|
||||
# It will then list you the Agent pid number (note that yes, this is a process now running the background, this is how
|
||||
it always will authenticate on your end, it is NECESSARY)
|
||||
|
||||
# Then we add the SSH private key to the ssh-agent.
|
||||
|
||||
ssh-add ~/.ssh/ed25519
|
||||
|
||||
# Then from the Github website on your profile page, go to settings and under SSH/GPG keys, add the SSH key including the SHA256 text,
|
||||
but not your email
|
||||
|
||||
#After you have successfully done so (you should see a client side different SSH key that it is associated with), you'll need to test
|
||||
your SSH connection:
|
||||
|
||||
ssh -T git@github.com
|
||||
|
||||
# You should then be prompted with a message like so:
|
||||
|
||||
> Hi username! You've successfully authenticated, but GitHub does not
|
||||
> provide shell access.
|
||||
|
||||
# You're now ready to go, just make sure to specify the origin as origin-ssh instead of origin when pushing to github:
|
||||
|
||||
git add <file(s)>
|
||||
git commit -m "commit message"
|
||||
git push origin-ssh main
|
||||
|
||||
It will then prompt you for your ssh passphrase, enter it and you've successfully committed to github using ssh!
|
||||
|
||||
If you would like to automate it so it doesn't ask for the passphrase (just don't forget your passphrase in case), you can set up
|
||||
automating putting in your passphrase like so:
|
||||
|
||||
ssh-add ~/.ssh/id_ed25519 &>/dev/null
|
||||
158
ssh_linode.html
Normal file
158
ssh_linode.html
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue