ssh命令详解

1、默认端口

sftp和ssh的默认端口是22

2、语法介绍

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]

3、常用参数详解

-b 绑定本地的ip地址,当本地网卡超过一个的时候,会用到这个参数

-D [bind_address:]port 绑定本地的ip地址和端口

-i identity_file 指定私钥文件

-l login_name 指定登录用户名

p port 指定远程机器的端口

4、常用登录方式

1、需要确认对方机器的指纹,然后再登录

[yiifung@master02 .ssh]$ ssh -p 22    [email protected]
The authenticity of host '192.168.168.128 (192.168.168.128)' can't be established.
ECDSA key fingerprint is SHA256:oU89b+M9k9nmrvN4S4tVfhnk2jKNcLUxu/n7D0id/6Q.
ECDSA key fingerprint is MD5:17:76:e5:ff:05:bc:5f:3d:3d:ff:6b:1a:3e:a6:ab:9c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.168.128' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Last login: Sat Jul  8 08:34:47 2023 from 192.168.168.130
[yiifung@master01 ~]$ 

2、忽略确认对方机器指纹的步骤,直接登录

[yiifung@master02 .ssh]$ ssh -p 22 -oStrictHostKeyChecking=no   [email protected]
Warning: Permanently added '192.168.168.128' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Last login: Sat Jul  8 08:33:42 2023 from 192.168.168.130
[yiifung@master01 ~]$

ssh -p 22 -oStrictHostKeyChecking=no   [email protected]
[yiifung@master02 .ssh]$ ssh -p 22 -oStrictHostKeyChecking=no   [email protected]
Last login: Sat Jul  8 08:32:39 2023 from 192.168.168.130
[yiifung@master01 ~]$

3、登录的过程中执行命令,执行完命令直接退出此次登录 (单引号一定要加上)

[yiifung@master02 .ssh]$ ssh -p 22    [email protected]   'cd test ; touch hello; ls -l '
[email protected]'s password: 
total 0
-rw-rw-r--. 1 yiifung yiifung 0 Jul  8 08:37 hello
-rw-rw-r--. 1 yiifung yiifung 0 Jul  8 04:39 test1
-rw-rw-r--. 1 yiifung yiifung 0 Jul  8 04:39 test2
[yiifung@master02 .ssh]$ 

你可能感兴趣的:(#,ssh,ssh,运维,centos,linux)