til/Applications/Network/OpenSSH.md

84 lines
1.1 KiB
Markdown
Raw Normal View History

2020-06-12 19:51:21 +00:00
# [OpenSSH](https://www.openssh.com/)
2020-12-01 16:10:02 +00:00
| Distribution | Package |
| ------------ | ------------------------------- |
| Arch Linux | `openssh` |
| Ubuntu | `openssh-client openssh-server` |
2021-04-03 16:58:41 +00:00
2020-06-12 19:51:21 +00:00
Edit `~/.ssh/config`:
```txt
Host myserver
2021-08-14 14:46:20 +00:00
Hostname server-address
User user
Port port
IdentityFile /path/to/private/key
2020-06-12 19:51:21 +00:00
```
Connect:
```sh
ssh -p port user@server-address
ssh myserver
```
## SSH key
2020-07-13 04:19:33 +00:00
Remove keys in `known_hosts`:
```sh
# Remove all
rm -rf ~/.ssh/known_hosts
# Remove only 1
ssh-keygen -R remote_host
```
### Copy local key to server
2020-06-12 19:51:21 +00:00
Generate key:
```sh
2021-08-14 14:40:23 +00:00
ssh-keygen -t ed25519 -C "your@email.com"
2020-06-12 19:51:21 +00:00
```
2020-07-13 04:19:33 +00:00
Start `ssh-agent`:
2020-06-12 19:51:21 +00:00
```sh
eval "$(ssh-agent -s)"
```
Add key:
```sh
2021-08-14 14:40:23 +00:00
ssh-add ~/.ssh/id_ed25519
2020-06-12 19:51:21 +00:00
```
2021-08-14 14:40:23 +00:00
Copying public key to server:
2021-08-14 14:46:20 +00:00
Linux:
2021-08-14 14:40:23 +00:00
```sh
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server-address
```
2021-08-14 14:46:20 +00:00
Windows:
```powershell
cat ~/.ssh/id_ed25519.pub | ssh user@server-address "cat >> ~/.ssh/authorized_keys"
```
2021-08-14 14:40:23 +00:00
#### ssh-add
2020-06-12 19:51:21 +00:00
Confirm key has been added:
```sh
ssh-add -l
```
2021-08-14 14:40:23 +00:00
Delete all keys:
2020-06-12 19:51:21 +00:00
```sh
2021-08-14 14:40:23 +00:00
ssh-add -D
2020-06-12 19:51:21 +00:00
```