Linux下SSH命令使用方法详解(摘自网络)
备注:检查自己的linux系统中是否已经安装了某一些软件的命令: rpm -qa | grep 软件名 例如 rpm -qa | grep vsftpd
1、查看SSH客户端版本 有的时候需要确认一下SSH客户端及其相应的版本号。使用ssh -V命令可以得到版本号。需要注意的是,Linux一般自带的是OpenSSH: 下面的例子即表明该系统正在使用OpenSSH: $ ssh -V OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
- 1、查看SSH客户端版本
有的时候需要确认一下SSH客户端及其相应的版本号。使用ssh -V命令可以得到版本号。需要注意的是,Linux一般自带的是OpenSSH: 下面的例子即表明该系统正在使用OpenSSH:
$ ssh -V
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
下面的例子表明该系统正在使用SSH2:
$ ssh -V
ssh: SSH Secure Shell 3.2.9.1 (non-commercial version) on i686-pc-linux-gnu
2、用SSH登录到远程主机
当你第一次使用ssh登录远程主机时,会出现没有找到主机密钥的提示信息。输入"yes"后,系统会将远程主机的密钥加入到你的主目录下的 .ssh/hostkeys下,这样你就可以继续操作了。示例如下:
1
2
3
4
5
6
7
8
|
localhost$ ssh -l jsmith remotehost.example.com
Host key not found from database.
Key fingerprint:
xabie-dezbc-manud-bartd-satsy-limit-nexiu-jambl-title-jarde-tuxum
You can get a public key‘s fingerprint by running % ssh-keygen -F publickey.pub on the keyfile.
Are you sure you want to continue connecting (yes/no)? Yes
Host key saved to /home/jsmith/.ssh2/hostkeys/key_22_remotehost.example.com.pub host key for remotehost.example.com,
accepted by jsmith Mon May 26 2008 16:06:50 -0700 jsmith@remotehost.example.com password: remotehost.example.com$
|
因为远程主机的密钥已经加入到ssh客户端的已知主机列表中,当你第二次登陆远程主机时,只需要你输入远程主机的登录密码即可。
1
2
3
|
localhost$ ssh -l jsmith remotehost.example.com
jsmith@remotehost.example.com password:
remotehost.example.com$
|
由于各种原因,可能在你第一次登陆远程主机后,该主机的密钥发生改变,你将会看到一些警告信息。出现这种情况,可能有两个原因:
o 系统管理员在远程主机上升级或者重新安装了SSH服务器
o 有人在进行一些恶意行为,等等。
在你输入“yes”之前呢,最佳的选择或许是联系你的系统管理员来分析为什么会出现主机验证码改变的信息,核对主机验证码是否正确。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
localhost$ ssh -l jsmith remotehost.example.com @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the- middle attack)!
It is also possible that the host key has just been changed.
Please contact your system administrator.
Add correct host key to ―/home/jsmith/.ssh2/hostkeys/key_22_remotehost.example.com.pub‖ to get rid of this message.
Received server key's fingerprint:
xabie-dezbc-manud-bartd-satsy-limit-nexiu-jambl-title-arde-tuxum
You can get a public key's fingerprint by running % ssh-keygen -F publickey.pub on the keyfile.
Agent forwarding is disabled to avoid attacks by corrupted servers.
Are you sure you want to continue connecting (yes/no)? yes
Do you want to change the host key on disk (yes/no)? yes
Agent forwarding re-enabled.
Host key saved to /home/jsmith/.ssh2/hostkeys/key_22_remotehost.example.com.pub host key for remotehost.example.com,
accepted by jsmith Mon May 26 2008 16:17:31 -0700 jsmith @remotehost.example.com's password: remotehost$
|
3、调试SSH客户端会话
当ssh连接出现问题时,我们需要通过查看调试信息来定位这些错误。一般来讲使用v选项(注意:是小写的v),即可查看调试信息。
没有SSH客户端调试信息的例子:
1
2
|
localhost$ ssh -l jsmith remotehost.example.com
warning: Connecting to remotehost.example.com failed: No address associated to the name
|
包含ssh调试信息的例子:
1
2
3
4
5
6
7
8
9
10
|
locaclhost$ ssh -v -l jsmith remotehost.example.com
debug: SshConfig/sshconfig.c:2838/ssh2_parse_config_ext:
Metaconfig parsing stopped at line 3.
debug: SshConfig/sshconfig.c:637/ssh_config_set_param_verbose:
Setting variable 嘠攀爀戀漀猀攀Mode' to FALSE'.
debug: SshConfig/sshconfig.c:3130/ssh_config_read_file_ext: Read 17 params from config file.
debug: Ssh2/ssh2.c:1707/main: User config file not found, using defaults. (Looked for /home/jsmith/.ssh2/ssh2_config')
debug: Connecting to remotehost.example.com, port 22… (SOCKS not used)
warning: Connecting to remotehost.example.com failed: No address associated to the name
[注:很多命令中,v选项对应的英文是 verbose,也就是详细的信息的意思。]
|
当你使用ssh从本机登录到远程主机时,你可能希望切换到本地做一些操作,然后再重新回到远程主机。这个时候,你不需要中断ssh连接,只需要按照第4点的步骤操作即可:
4、用SSH退出符切换SSH会话
这个技巧非常实用。尤其是远程登陆到一台主机A,然后从A登陆到B,如果希望在A上做一些操作,还得再开一个终端,很是麻烦。
当你使用ssh从本机登录到远程主机时,你可能希望切换到本地做一些操作,然后再重新回到远程主机。这个时候,你不需要中断ssh连接,只需要按照如下步骤操作即可:
当你已经登录到了远程主机时,你可能想要回到本地主机进行一些操作,然后又继续回到远程主机。在这种情况下,没有必要断开远程主机的会话,你可以用下面的办法来完成:
1.登入远程主机:
localhost$ ssh -l jsmith remotehost
2.已连接远程主机:
remotehost$
3.要临时回到本地主机,输入退出符号:“~”与“Control-Z”组合。
当你输入“~”你不会立即在屏幕上看到,当你按下<Control-Z>并且按回车之后才一起显示。如下,在远程主机中以此输入“~<Control-Z>”
remotehost$ ~^Z
[1]+ Stopped ssh -l jsmith remotehost
localhost$
4.现在你已经退回到了本地主机,ssh远程客户端会话就在UNIX后台中运行,你可以向下面那样查看它:
localhost$ jobs
[1]+ Stopped ssh -l jsmith remotehost
5. 你可以将后台运行的ssh会话进程切换到前台,重新回到远程主机,而无需输入密码
localhost$ fg %1
ssh -l jsmith remotehost
remotehost$
5、用SSH退出字符会话,显示信息
要想取得一些关于当前会话有用的信息,可以按以下方式完成。不过这只能在SSH 2 客户端上使用。
登录到远程服务器
localhost$ ssh -l jsmith remotehost
如下所示,在远程服务器上,输入ssh退出字符~并输入s。这样会显示出很多有关当前ssh连接的有用信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
remotehost$ [注:当你在命令行上输入~s时,它是不可见的.]
remote host: remotehost
local host: localhost
remote version: SSH-1.99-OpenSSH_3.9p1
local version: SSH-2.0-3.2.9.1 SSH Secure Shell (non-commercial)
compressed bytes in: 1506
uncompressed bytes in: 1622
compressed bytes out: 4997
uncompressed bytes out: 5118
packets in: 15
packets out: 24
rekeys: 0
Algorithms:
Chosen key exchange algorithm: diffie-hellman-group1-sha1
Chosen host key algorithm: ssh-dss
Common host key algorithms: ssh-dss,ssh-rsa
Algorithms client to server:
Cipher: aes128-cbc
MAC: hmac-sha1
Compression: zlib
Algorithms server to client:
Cipher: aes128-cbc MAC: hmac-sha1
Compression: zlib
localhost$
|
Linux下SSH命令使用方法详解(摘自网络)的更多相关文章
- Linux下nl命令的用法详解
Linux中nl命令和cat命令很像,不过nl命令会打上行号,属于比较不常用的命令,下面随小编一起来了解下这个鲜为人知的nl命令吧. nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文 ...
- [转帖]Linux 下 DD 命令的使用详解
https://blog.csdn.net/noviblue/article/details/56012275 一.dd命令的解释 dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换. 注 ...
- Windows性能监视器之CPU、硬盘、IO等监控方法详解-摘自网络
一般操作系统性能主要涉及到的问题主要有:处理器使用情况.内存占有量.磁盘I/0操作以及网络流量等. 查看Windows性能情况,大部分情况下是通过 “Windows任务管理器”,可以通过在 ”命令行” ...
- 【转】Linux下Android ADB驱动安装详解
原文网址:http://blog.csdn.net/zhenwenxian/article/details/5901350 Linux下Android ADB驱动安装详解 概述 最近由于内置的合作商比 ...
- 【Linux学习】Linux下用户组、文件权限详解
原文地址:http://www.cnblogs.com/123-/p/4189072.html Linux下用户组.文件权限详解 用户组 在linux中的每个用户必须属于一个组,不能独立于组外.在li ...
- 莱特币ltc在linux下的多种挖矿方案详解
莱特币ltc在linux下的多种挖矿方案详解 4.0.1 Nvidia显卡Linux驱动Nvidia全部驱动:http://www.nvidia.cn/Download/index.aspx?lang ...
- telnet 命令使用方法详解,telnet命令怎么用
telnet 命令使用方法详解,telnet命令怎么用? 文章类型:电脑教程 原创:天诺时空 什么是Telnet? 对于Telnet的认识,不同的人持有不同的观点,可以把Telnet当成一种通信协 ...
- (转)Mysql数据库之Binlog日志使用总结Linux下用户组、文件权限详解
Linux下用户组.文件权限详解 原文:http://blog.csdn.net/sdulibh/article/details/51566772 用户组 在linux中的每个用户必须属于一个组,不能 ...
- 【Linux开发】Linux下jpeglib库的安装详解
Linux下jpeglib库的安装详解 首先要下载所需的库压缩包:jpegsrc.v6b.tar.gz或 jpegsrc.v8b.tar.gz 然后将下载的压缩包随便放在和解压到你喜欢的地方. # t ...
随机推荐
- "工作激发了我的热情,并不断激励着我” - SAP成都研究院Jerry Wang
SAP 为员工提供了与 SAP的优秀人才以及全球客户和合作伙伴共事的绝佳机会.我相信,只要你努力工作,充满激情,你就能在这里获得成功. -- Jerry Wang 加入SAP 我是从中国电子科技大学的 ...
- Vue父组件像子组件传值--自定义属性
这里有个注意的地方,Vue实例控制app DIV 大组件,我们在div中天加小组件的时候,传值需要创建自定义的属性 之后在通过props:[‘属性名’] 来把父元素data中的数据传递给子组件 < ...
- 【SpringMVC】Validation校验
一.概述 二.步骤 2.1 引入 Hibernate Validator 2.2 配置 2.3 创建CustomValidationMessages 2.4 校验规则 2.5 捕获错误 2.6 在页面 ...
- Linux——发行版
主流发行版 1. Red Hat Linux Red Hat 公司一直是Linux 乃至开源世界的领导者.其有两个不同的发行版本: 一个商用版,称为Red Hat Enterprise Linux,专 ...
- [Python]pip install offline 如何离线pip安装包
痛点:目标机器无法连接公网,但是能使用rz.sz传输文件 思路:在能上网的机器是使用pip下载相关依赖包,然后传输至目标机器,进行安装 0. Install pip: http://pip-cn.re ...
- Python_if语句
1.if语句: color='红色' if color=='蓝色': print('我是蓝色') elif color=='红色': print('我是红色') else : print('未知') ...
- MySQL分布式数据库架构:分库、分表、排序、分页、分组、实现教程
MySQL分库分表总结: 单库单表 : 单库单表是最常见的数据库设计,例如,有一张用户(user)表放在数据库db中,所有的用户都可以在db库中的user表中查到. 单库多表 : 随着用户数量的增加, ...
- Java关键字—final
final—不可变的,用来说明最终属性,表明一个类不能派生出子类,或者成员方法不能被覆盖,或者成员域的值不能被改变. 修饰范围: 1.修饰类,被final关键字修饰的类无法被继承: 2.修饰方法,被f ...
- 创建第一kubernetes应用以及基本操作(六)
1.创建一个测试用的deployment kubectl run net-test --image=alpine --replicas= sleep 2.查看获取IP情况 [root@linux ~] ...
- 系统间HTTP调用代码封装
痛点 最近接手一个老项目,这个项目几经转手,到我这里时,发现代码的可阅读性实在是很差,对于一个有点代码洁癖的我来说,阅读起来实在是很难受.其中一个痛点,现在就拉出来讲讲.该项目需要与另外一个项目进行业 ...