Update ssh.md

This commit is contained in:
小弟调调 2023-05-27 11:55:21 +08:00 committed by GitHub
parent 7e5938af49
commit 119f80ab24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 0 deletions

View File

@ -58,6 +58,55 @@ ssh-keygen -f keyfile -i -m key_format -e -m key_format # key_format: RFC4716/SS
ssh-copy-id user@ip:port # 将当前用户的公钥复制到需要 ssh 的服务器的 ~/.ssh/authorized_keys之后可以免密登录 ssh-copy-id user@ip:port # 将当前用户的公钥复制到需要 ssh 的服务器的 ~/.ssh/authorized_keys之后可以免密登录
``` ```
连接远程服务器
```shell
ssh username@remote_host
```
2. 连接远程服务器并指定端口
```shell
ssh -p port username@remote_host
```
使用密钥文件连接远程服务器
```shell
ssh -i path/to/private_key username@remote_host
```
在本地执行远程命令
```shell
ssh username@remote_host "command"
```
在本地复制文件到远程服务器
```shell
scp path/to/local_file username@remote_host:/path/to/remote_directory
```
在远程服务器复制文件到本地
```shell
scp username@remote_host:/path/to/remote_file path/to/local_directory
```
在本地端口转发到远程服务器
```shell
ssh -L local_port:remote_host:remote_port username@remote_host
```
在远程服务器端口转发到本地
```shell
ssh -R remote_port:local_host:local_port username@remote_host
```
### 背后故事 ### 背后故事
> 英文Tatu Ylonen > 英文Tatu Ylonen