###### tags: `linux`
# SSH fundimental
## Normal access through ssh
SSH has both server and client side. we can install thorugh following command
```
// server
sudo apt install openssh-server
// client
sudo apt install openssh-client
```
Normal unix base system has deault client installed
When we want to access an ssh server, we can simply use ssh command as below
```
ssh <userName>@<ipaddress>
```
## SSH config
All the ssh related ssh files are located in ~/.ssh folder including
- known_hosts: the historical records that this client has already accessed
- config: The config file of ssh
- others: Including pubkey and private key which will be explain in next section
## Publickey and Privatekey
The reasons why we need public key are
1. being able to let any kind of ssh server to recognize the client. Then access the server without inputing pwd
2. most of online tool or vps currently support such login method (including github and gcp)
### Checking existing key
```
ls ~/.ssh
```

As can be seen, I have already have pubkey (id_rsa.pub) and private key (id_rsa)
If there are no such files, we can create one by
```
ssh-keygen
```

### Upload the pubkey to server side
#### Upload by comand
Because server side needs to know which client is allowed to access. It needs to have the publickey of the client as client's id.
Then we use the following cmd
```
ssh-copy-id <serverUserName>@<serverIp>
```
Then we will be able to see that the there will be a file called authorized_keys including the client's pubkey shows up on ~/.ssh folder

#### Upload to GCP
We just check the publickey and pass it in google interface

Then we can login through
```
ssh -i eric_rsa ericLee@<ipaddress>
```
## set up the config file
```
Host services-v2
HostName <ipaddress>
User ericLee
Port 22
IdentityFile ~/.ssh/eric_rsa
```
Than we can easily access the GCP service with following cmd
```
ssh services-v2
```
