首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

【Linux】一步一步学Linux——ssh命令(176)

  • 23-11-18 13:20
  • 2076
  • 7009
blog.csdn.net

00. 目录

文章目录

    • 00. 目录
    • 01. 命令概述
    • 02. 命令格式
    • 03. 常用选项
    • 04. 参考示例
    • 05. 附录

01. 命令概述

ssh命令是openssh套件中的客户端连接工具,可以给予ssh加密协议实现安全的远程登录服务器,实现对服务器的远程管理。

02. 命令格式

格式:ssh [选项] [参数]
  • 1

03. 常用选项

-1	强制使用ssh协议版本1
-2	强制使用ssh协议版本2
-4	强制使用IPv4地址
-6	强制使用IPv6地址
-A	开启认证代理连接转发功能
-a	关闭认证代理连接转发功能
-b<IP地址>	使用本机指定的地址作为对位连接的源IP地址
-C	请求压缩所有数据
-F<配置文件>	指定ssh指令的配置文件,默认的配置文件为“/etc/ssh/ssh_config”
-f	后台执行ssh指令
-g	允许远程主机连接本机的转发端口
-i<身份文件>	指定身份文件(即私钥文件)
-l<登录名>	指定连接远程服务器的登录用户名
-N	不执行远程指令
-o<选项>	指定配置选项
-p<端口>	指定远程服务器上的端口
-q	静默模式,所有的警告和诊断信息被禁止输出
-X	开启X11转发功能
-x	关闭X11转发功能
-y	开启信任X11转发功能
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

04. 参考示例

4.1 登录远程服务器

[deng@localhost ~]$ ssh 172.16.0.76
The authenticity of host '172.16.0.76 (172.16.0.76)' can't be established.
ECDSA key fingerprint is SHA256:YheY5RH3PZ27UMYxdPwhraYfS4bCK/p3+xwdWL0O9WQ.
ECDSA key fingerprint is MD5:27:a1:b7:c7:df:7d:91:04:40:bd:e9:79:bb:98:8f:e4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.0.76' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Last login: Thu Aug 22 22:06:22 2019 from 172.16.0.51
[deng@localhost ~]$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4.2 指定用户登录远程服务器

[deng@localhost ~]$ ssh -l deng 172.16.0.76
[email protected]'s password: 
Last login: Thu Aug 22 22:06:33 2019 from 172.16.0.76
[deng@localhost ~]$ 
  • 1
  • 2
  • 3
  • 4

4.3 查看远程服务器分区列表

[deng@localhost ~]$ ssh -l root 172.16.0.76 /sbin/fdisk -l
[email protected]'s password: 

磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000cc727

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     8800255     4194304   82  Linux swap / Solaris
/dev/sda3         8800256   209715199   100457472   83  Linux
[deng@localhost ~]$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

4.4 强制使用ssh协议版本2

[deng@localhost ~]$ ssh -2 -l root 172.16.0.76
[email protected]'s password: 
Last login: Thu Aug 22 21:42:57 2019
[root@localhost ~]# 
  • 1
  • 2
  • 3
  • 4

4.5 开启认证代理连接转发功能

[root@localhost ~]# ssh -A -l root 172.16.0.76
The authenticity of host '172.16.0.76 (172.16.0.76)' can't be established.
ECDSA key fingerprint is SHA256:YheY5RH3PZ27UMYxdPwhraYfS4bCK/p3+xwdWL0O9WQ.
ECDSA key fingerprint is MD5:27:a1:b7:c7:df:7d:91:04:40:bd:e9:79:bb:98:8f:e4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.0.76' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Last login: Thu Aug 22 22:10:56 2019 from 172.16.0.76
[root@localhost ~]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4.6 关闭认证代理连接转发功能

[root@localhost ~]# ssh -a -l root 172.16.0.76 
[email protected]'s password: 
Last login: Thu Aug 22 22:11:31 2019 from 172.16.0.76
[root@localhost ~]# 
  • 1
  • 2
  • 3
  • 4

4.7 指定用户名登录(二)

[root@localhost ~]# ssh [email protected]
[email protected]'s password: 
Last login: Thu Aug 22 22:12:26 2019 from 172.16.0.76
[root@localhost ~]# 
  • 1
  • 2
  • 3
  • 4

4.8 指定端口登录远程服务器

[root@localhost ~]# ssh -p 22 [email protected]  
[email protected]'s password: 
Last login: Thu Aug 22 22:13:31 2019 from 172.16.0.76
[root@localhost ~]# 
  • 1
  • 2
  • 3
  • 4

4.9 通过代理登录

[root@localhost ~]# ssh -D 7576 [email protected]
[email protected]'s password: 
Last failed login: Thu Aug 22 22:15:00 CST 2019 from 172.16.0.76 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Thu Aug 22 22:14:03 2019 from 172.16.0.76
[root@localhost ~]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4.10 执行远程指令

[root@localhost ~]# ssh [email protected] date
[email protected]'s password: 
2019年 08月 22日 星期四 22:15:56 CST
[root@localhost ~]# 
  • 1
  • 2
  • 3
  • 4

4.11 在远程主机运行一个图形界面的程序

[root@localhost ~]# ssh -X [email protected]
[email protected]'s password: 
  • 1
  • 2

4.12 绑定源地址

[root@localhost ~]# ssh -b 172.16.0.76 [email protected]
[email protected]'s password: 
Last login: Thu Aug 22 22:20:55 2019 from 172.16.0.76
[deng@localhost ~]$ 
  • 1
  • 2
  • 3
  • 4

4.13 对所有数据请求压缩

[deng@localhost ~]$ ssh -C [email protected]
[email protected]'s password: 
Last login: Thu Aug 22 22:22:00 2019 from 172.16.0.76
[deng@localhost ~]$ ls
  • 1
  • 2
  • 3
  • 4

4.14 打开调试模式

[deng@localhost ~]$ ssh -v [email protected]
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to 172.16.0.76 [172.16.0.76] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/deng/.ssh/id_rsa type -1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

4.15 静默模式,所有的警告和诊断信息被禁止输出

[deng@localhost ~]$ ssh -q [email protected]
[email protected]'s password: 
Last failed login: Thu Aug 22 22:23:52 CST 2019 from 172.16.0.76 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Thu Aug 22 22:22:34 2019 from 172.16.0.76
[deng@localhost ~]$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

05. 附录

参考:【Linux】一步一步学Linux系列教程汇总

注:本文转载自blog.csdn.net的沧海一笑-dj的文章"https://blog.csdn.net/dengjin20104042056/article/details/100038958"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top