public_key
(id_rsa.pub
) & private_key
(id_rsa
).private_key
can understand public_key
.public_key
.private_key
to understand (decrypt) remote's messages.Windows: Using below command, if it asks for a location, indicate C:\\Users\\dinha\\.ssh\\
Linux: /home/thi/.ssh/
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# without email
ssh-keygen -t rsa -f ~/.ssh/id_rsa.home
Create key with different names, e.g. id_rsa.home
, id_rsa.work
.
Add to ~/.ssh/config
,
Host home
Hostname home.example.com
IdentityFile ~/.ssh/id_rsa.home
User <your home acct>
#
Host work
Hostname work.example.com
IdentityFile ~/.ssh/id_rsa.work
User <your work acct>
Add to ssh-agent (don't need to retype password again)
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa.home
ssh-add ~/.ssh/id_rsa.work
Don't forget to clone you repo with git
instead of https
.
Suppose that we wanna connect to a remote host username@remote.com
from a local machine.
C:/Users/dinha/.ssh
(Windows) and ~/.ssh
(Linux) (something like id_rsa.pub
) (copy its content).~/.ssh
, open file authorized_keys by vim authorized_keys
W
)I
to enter to the editing mode, press Enter
for a new line.ESC
and then type :wq
to quick and save.ssh remote_username@remote_host
ssh remote_username@remote_host -p remote_port
# CHECK VERSION
ssh -V
# DISCONNECT
exit