用法:

usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-e escape_char] [-F configfile]
           [-I pkcs11] [-i identity_file]
           [-L [bind_address:]port:host:hostport]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-R [bind_address:]port:host:hostport] [-S ctl_path]
           [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]

常见参数:

  • -D: 绑定本地端口
  • -F: 指定config文件的位置
  • -l: 登录用户名
  • -p: 远程端口
  • -N: 只转发端口,不执行远程命令,proxy时的常用参数
  • -i: key的解密文件路径,通常指~/.ssh/idrsa ~/.ssh/idecdsa ~/.ssh/id_dsa
  • -C: 压缩传输
  • -c: 选择用于加密连接的加密方式
  • -1: 只使用protocol 1连接
  • -2: 只使用protocol 2链接
  • -4: 只使用ipv4链接
  • -6: 只使用ipv6链接

普通的登录

ssh user@remotehost
or
ssh -l user remotehost

proxy

ssh -C -N -D localport username@hostname -p remoteport

mount

sshfs -p remoteport user@localhost:/remotepath localpath

将远程主机的 remotepath 挂载到本地 localpath

umount

fusermount -u localpath

卸载挂载文件

upload

scp localpath/file user@localhost:/remotepath

上传本地 file 到远程的 remotepath

download

scp username@localhost:/remotepath/file localpath

下载远程 file 文件到本地

一般而言,对于常用参数,我们将之写入到 .ssh/config 文件中是个很常用的做法

Host name
    IdentityFile    ~/.ssh/your-private-key
    HostName    ip
    port    21
    User    havanna

Compression yes

如此,连接的时候只要如下即可

ssh name