Openssh 常见用法

用法:

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]]
           [[email protected]]hostname [command]

常见参数:

普通的登录

ssh [email protected]
or
ssh -l user remotehost

proxy

ssh -C -N -D localport [email protected] -p remoteport

mount

sshfs -p remoteport [email protected]:/remotepath localpath

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

umount

fusermount -u localpath

卸载挂载文件

upload

scp localpath/file [email protected]:/remotepath

上传本地 file 到远程的 remotepath

download

scp [email protected]:/remotepath/file localpath

下载远程 file 文件到本地

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

Host name
    IdentityFile    ~/.ssh/your-private-key
    HostName        ip
    Port            port
    User            username

Host *
    Compression     yes

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

ssh username

ssh-agent

ssh-agent 一般人用不到,不过还是挺有用的,概念不介绍了。用法也是很简单,Mac 用户编辑 .ssh/config 文件

Host host1
    IdentityFile    ~/.ssh/your-private-key
    HostName        ip/domain
    ForwardAgent    yes
    Port            port
    User            username

Host *
    AddKeysToAgent  yes
    UseKeychain     yes
    Protocol        2
    Compression     yes

好了,当你 ssh host1 之后,可以登陆同样公钥的第三台机器了。