[ ssh 基础操作 ]
local$ ssh user@remote -p port
// -p 指定端口,默认22, remove是远程机的ip
[ 免密登陆 ]
local$ ssh-keygen
// 本条命令会生成一对秘钥
local$ ssh-copy-id user@remote -p port
// 这条命令会将公钥上传到远程机,输入远程机登陆密码即可完成
// 完成后登陆远程机就不用再输入密码了
[ 配置别名 ]
- 将以下内容追加到 ~/.ssh/config 中即可完成配置
Host web
Hostname remote // 远程机的ip地址
pUser user // 远程机用户的用户名
Port port // 默认22,可以省略不写
local$ ssh web
[ scp 传输文件 ]
local$ scp dir/file web:dir/
// 将本地目录 dir 中的 file 传输到远程机 web 的 dir 目录下
local$ scp web:dir/file dir/file
// 将远程机 web的 dir 目录中的 file 传输到本地目录 的 dir 目录下