- Local creates
public_key(id_rsa.pub) &private_key(id_rsa).
- Only
private_keycan understandpublic_key.
- Remote sends messages encrypted based on
public_key.
- Local has to use
private_keyto understand (decrypt) remote's messages.
- Windows: Using below command, if it asks for a location, indicate
C:\Users\dinha\.ssh\
- Linux:
/home/thi/.ssh/
- Create key with different names, e.g.
id_rsa.home,id_rsa.work.
- Add to
~/.ssh/config
- Add to ssh-agent (don't need to retype password again)
- Don't forget to clone you repo with
gitinstead ofhttps.
Suppose that we wanna connect to a remote host
[email protected] from a local machine.- On local machine, copy public key at
C:/Users/dinha/.ssh(Windows) and~/.ssh(Linux) (something likeid_rsa.pub) (copy its content).
- On remote server (Linux), go to
~/.ssh, open file authorized_keys byvim authorized_keys - Be carefull, you can modify the current keys!
- Go to the end of this file (by
W) - Press
Ito enter to the editing mode, pressEnterfor a new line. - Using mouse to copy/paste the key in the 1st step (on your local machine).
- Note that, each key stays in a separated line.
ESCand then type:wqto quick and save.- Try to connect again!
Below are some popular commands (ref):
C: use data compression.
f: Requests ssh to go to background just before command execution
L <local-port>:remote.com:80: local port forwarding (ref).
N: Do not execute a remote command. This is useful for just forwarding ports
p <port>: port to connect.
q: quiet mode.
v: verbose mode.
X: running GUI remote app locally.
