赞
踩
ssh命令是Secure Shell的简写,其功能是安全地远程连接服务器,ssh是OpenSSH套件中的客户端连接工具,通过SSH加密协议进行远程主机访问,并对远程服务器进行管理。
ssh命令的基本语法格式如下:
- ssh [选项] 主机名或IP地址
-
- 或者
-
- ssh [选项] 用户名@主机名或IP地址
常用选项如下:
选项 | 含义 |
-p | 设置远程服务器上的端口号 |
-q | 静默执行模式 |
-b | 设置本机对外提供服务的IP地址 |
-s | 请求远程主机上的子系统调用 |
-c | 设置会话的密码算法 |
-v | 显示执行过程详细信息 |
-C | 压缩所有数据 |
-f | 后台执行ssh命令 |
-i | 设置密钥文件 |
-l | 设置登录用户名 |
-V | 显示版本信息 |
实例演示
1、远程连接主机
远程连接Linux服务器时,若未指定端口,默认端口号为22。若未指定用户名,默认用户名为当前客户机登录的用户名。
首次连接时,还需要对远程连接进行确认,然后要求输入该远程连接服务器的密码。
- [root@node1 ~]# ssh 218.0.0.44
- The authenticity of host '218.0.0.44 (218.0.0.44)' can't be established.
- ED25519 key fingerprint is SHA256:WkIRCc+3d0QPU70jkP6YnZkDwENYRK1bXffw3/ZuXTs.
- This key is not known by any other names
- Are you sure you want to continue connecting (yes/no/[fingerprint])? yes #此处输入yes
- Warning: Permanently added '218.0.0.44' (ED25519) to the list of known hosts.
- Authorized users only. All activities may be monitored and reported.
- root@218.0.0.44's password: #此处输入远程服务器上root的密码
-
- ……此处省略其它输出……
2、指定用户名和端口进行远程连接
- #可以使用-l指定用户名,-p指定连接端口
- [root@node1 ~]# ssh -l zhangsan -p 22 218.0.0.44
-
- Authorized users only. All activities may be monitored and reported.
- zhangsan@218.0.0.44's password: #此处输入远程服务器上zhangsan的密码
也可以使用以下形式远程连接服务器
- # 也可以使用以下命令形式。若端口号为22,则可以不用写
- [root@node1 ~]# ssh zhangsan@218.0.0.44 22
-
- Authorized users only. All activities may be monitored and reported.
- zhangsan@218.0.0.44's password:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。