---
# System prepended metadata

title: SSH public key

---

# SSH public key

## On local Machine
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeiDjlfrKukWlM0j2mt4eSRrj4/6whxvBaR0LQEolIeMhlsDOwRm2CvMl4Ml5uAtitGZHM6aq9sCZVBdkDwPxf6C9b/36mJK6B0LGQPX7XB52iOlnpg2f6J+nT122suTwuoWOwDu1hiArfM+3OF8AzEIr+abxv5e+L0SwuL3sBMgCh5PXD+S6BD7PI7Cvi3ckALo9hR7e6idRdSI/J7WVXxJIU6RohxDYVoK/FS55WMLOXksg38lURHtfXA2qgXx8qTwDr1a8VVYXJl03/yyVdnWJ6ip2RKyzVRycqlHkBBY3pLYWUFUCoeaERYxcrzrfhLP8Uj6ePLOTxWSvMni3d rsa-key-20230520

### Step 1 - Generate Key
```
ssh-keygen
```
keep pressing Enter for the follwoing configuration.
I choose to not set an extra password for this

### Step 2 - Copy Your Public Key to Server

```
ssh-copy-id -i <YourHomePath>/.ssh/id_rsa.pub lab530@140.112.19.218 -p 40000
```

The Public key should be store at ~/.ssh/authorized_keys in remote server


## On Remote Server
### To Disable passward login

```
sudo vim /etc/ssh/sshd_config
```
Set to PasswordAuthentication no
Set to PubkeyAuthentication yes
```
service ssh restart
```

If you want to use public key to connect to remote server via VScode, you need to add the private key file path to ssh configuration: 
![](https://i.imgur.com/4ftYCBP.png)
The Idenetity File point to your private key file


