I used to enter the password when pushing file to Github or connecting to remote server. I always feel this step redundant and recently came to konw that SSH is a good solution. I want to record these steps in case of need later.
SSH for Github
- Running the following command:
1
2
ssh-keygen -t rsa
<keep clicking 'Enter' if system asks you for actions>
You can also add -C "your_email@example.com"
at the end of ssh-keygen -t rsa
to make a copy of the ssh-key by email.
- Check your ~/.ssh folder and there is a
id_rsa.pub
- Add the key to github account.
- Change to the git repo folder and run:
git remote set-url origin git@github.com:username/your-repository.git
, here theorigin
could also bemaster
. - Then try
git push
and this time it shouldn’t require you to enter password anymore.
Remote Server
- If you already have a key, then run
ssh-copy-id <your server address>
- If you don’t have, you can just follow the step 1&2 for github and do the above step.
- You can directly log in when next time you try to connect server with
ssh <server>
.
More details please see FOR GITHUB and SSH FOR UBUNTU.