Secure Shell
发表于|更新于|Tools
|字数总计:822|阅读时长:3分钟|阅读量:
SSH, Secure Shell
- 查看已有公钥
1 | cd ~/.ssh # 进入目录 |
1 | cat ~/.ssh/id_rsa.pub # 显示公钥 |
- 生成新的密钥
1 | ssh-keygen -t rsa -b 4096 -f ~/.ssh/newsshkey |
- 将公钥上传至服务器
1 | ssh-copy-id -i ~/.ssh/newsshkey.pub -p port User@HostName |
这个命令会将公钥中的内容 copy 至服务器上 ~/.ssh/authorized_keys
文件中
- ssh config
1 | Host [name] # 配置别名 |
- 使用
1 | ssh [name] |
在登陆时可能会收到如下报错信息:
1 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
这个错误信息表明你的 ~/.ssh/id_rsa.pub
文件的权限设置过为公开, 这是不安全的. SSH密钥应该被设置为仅当前用户可以读写, 而其他任何用户都不能访问. 执行以下命令来修改权限, 确保你的SSH公钥的权限是安全的:
1 | chmod 600 ~/.ssh/id_rsa.pub |
这个命令会将.ssh/id_rsa.pub文件的权限设置为只有 “所有者” 有读权限.
连接远端仓库时指定私钥路径
1 | GIT_SSH_COMMAND="ssh -i /path/to/id_rsa" git clone git@github.com:xxx |
Linux Command
Check System Info
1 | (base) zwx@7049GP-TRT:/$ cat /etc/os-release |
Check Shell Implementation
1 | (base) zwx@7049GP-TRT:/$ echo $SHELL |
SSH with VS Code
Visual Studio Code Remote - SSH | YouTube
Remote-SSH | VS Code Docs
如何传输文件
打包压缩一个文件夹
1 | # server1 |
解压缩一个 tar.gz 包
1 | # server2 |
使用 -C 指定目录
1 | tar -xvpf package.tar.gz -C /path/to/destination/ |
使用多线程, 需要安装 pigz
1 | tar --use-compress-program=pigz -xvpf package.tar.gz -C /path/to/destination/ |
使用 rsync
命令 remote synchronize 同步一个文件
1 | # synchronize file from local to remote |
The source and destination cannot both be remote.
注意远端和本地的区分
通过 -r
参数来同步一个文件夹
1 | rsync -r /path/to/srcdir User2@HostName2:/path/to/destination/ |
文章作者: 文羊羽
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 文羊羽!