Linux ssh的使用
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 ssh的使用的更多相关文章
- 如何通过linux ssh远程linux不用输入密码登入
如何通过一台linux ssh远程其他linux服务器时,不要输入密码,可以自动登入.提高远程效率,不用记忆各台服务器的密码. 工具/原料 ssh,ssh-keygen,scp 方法/步骤 首 ...
- windows 和 linux ssh互连
从windows连接到linux: linux开启sshd服务即可,主要是windows的配置如下: 1.使用软件,putty可以直接使用 2.使用cmd控制台连接linux,安装SSH Secure ...
- Linux SSH安全策略限制IP登录方法(转)
本文介绍了Linux SSH安全策略限制IP登录的两种方法.具体如下: 方法一: 首先需要限制登录的ip(或者如果需要自己本地登录,查看最后登录ip即可) Vim /etc/hosts.allow 输 ...
- Linux SSh scp使用【远程文件/目录的传输】
一:Linux ssh scp的简介及作用: scp就是secure copy的简写,用于在linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器. 有时我们 ...
- 解Linux SSH命令大全,新手必看SSH命令
下面介绍一些基本的常用的Linux SSH命令,都是一些很简单的Linux SSH命令,新手掌握了这几个,一般管理一般的vps或者linux主机就可以了! 我们的教程介绍了putty的使用方法 ...
- Linux ssh登陆慢的两种原因分析
Linux ssh登陆慢的两种原因分析 如果做运维就一定会遇到ssh登陆Linux服务器慢的问题,问题比较好解决,一般Google之后有很多文章都告诉你解决方法,但是很少有文章分析为什么会慢,这篇文章 ...
- linux ssh 报错failed - POSSIBLE BREAK-IN ATTEMPT
linux ssh 报错failed - POSSIBLE BREAK-IN ATTEMPT 问题故障: 今天在新租的虚拟机上,发现ssh登陆机器的时候报错,如下: [root@pictures_ne ...
- Linux - ssh 连接问题
SSH 连接方式 ssh -p 22 user@192.168.1.209 # 从linux ssh登录另一台linux ssh -p 22 root@192.168.1.209 CMD # 利用ss ...
- Linux SSH远程文件/目录 传输
Linux SSH远程文件/目录传输命令scp 2010年08月6日 上午 | 作者:VPS侦探 相信各位VPSer在使用VPS时会经常在不同VPS间互相备份数据或者转移数据,大部分情况下VPS上都已 ...
- Linux SSH登录服务器报ECDSA host key "ip地址" for has changed and you have requested strict checking.错误
Linux SSH命令用了那么久,第一次遇到这样的错误:ECDSA host key "ip地址" for has changed and you have requested ...
随机推荐
- 『Python Kivy』官方乒乓球游戏示例解析
本篇文章用于对Kivy框架官方所给出的一个「乒乓球」小游戏的源码进行简单地解析.我会尽可能的将方方面面的内容都说清楚.在文章的最下方为官方所给出的这个小游戏的教程以及游戏源码. 由于篇幅所限,本文只简 ...
- Spring框架中ModelAndView、Model、ModelMap的区别
转自:http://blog.csdn.net/liujiakunit/article/details/51733211 1. Model Model 是一个接口, 其实现类为ExtendedMode ...
- localStorage简析
声明:引用自http://www.cnblogs.com/st-leslie/p/5617130.html 一.什么是localStorage.sessionStorage 在HTML5中,新加入了一 ...
- Gradle下载依赖jar包位置修改
gradle会下载相关需要依赖的jar包,默认的本地存放地址是:C:/Users/(用户名)/.gradle/caches/modules-2/files-2.1,很多人和我一样不愿意放在C盘,所以需 ...
- JQuery UI 日历加时间
写一个面试时间通知.用jquery ui 具体功能已经可以了,不过样式还没调 一.需要引入的文件,这些可以到官网下载 <link rel="stylesheet" href= ...
- Spring实战第九章学习笔记————保护Web应用
保护Web应用 在这一章我们将使用切面技术来探索保护应用程序的方式.不过我们不必自己开发这些切面----我们将使用Spring Security,一种基于Spring AOP和Servlet规范的Fi ...
- ADVICE FOR SHORT-TERM MACHINE LEARNING RESEARCH PROJECTS(短期机器学习研究的建议)
– Tim Rocktäschel, Jakob Foerster and Greg Farquhar, 29/08/2018 Every year we get contacted by stude ...
- php+Mysql分页 类和引用详解
一下内容为专用于分页的类以及具体的方法和解析.<?php class Page { private $total; //数据表中总记录数 private $listRows; //每页显示行数 ...
- HDU 4744 Starloop System(最小费用最大流)(2013 ACM/ICPC Asia Regional Hangzhou Online)
Description At the end of the 200013 th year of the Galaxy era, the war between Carbon-based lives a ...
- python 生成csv乱码问题解决方法
需求背景 最近为公司开发了一套邮件日报程序,邮件一般就是表格,图片,然后就是附件.附件一般都是默认写到txt文件里,但是PM希望邮件里的附件能直接用Excel这种软件打开,最开始想保存为Excel,但 ...