2024年5月16日发(作者:)
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下,这样你就可以继续
操作了。示例如下:
localhost$ ssh -l jsmith
1 Host key not found from database.
2 Key fingerprint:
3 xabie-dezbc-manud-bartd-satsy-limit-nexiu-jambl-title-jarde-tuxum
4
You can get a public key„s fingerprint by running % ssh-keygen -F on the keyfile.
5 Are you sure you want to continue connecting (yes/no)? Yes
6 Host key saved to /home/jsmith/.ssh2/hostkeys/key_22_ host key for
7 ,
8 accepted by jsmith Mon May 26 2008 16:06:50 -0700 jsmith@ password:
$
因为远程主机的密钥已经加入到ssh客户端的已知主机列表中,当你第二次登陆远程主
机时,只需要你输入远程主机的登录密码即可。
localhost$ ssh -l jsmith
jsmith@
password:
$
由于各种原因,可能在你第一次登陆远程主机后,该主机的密钥发生改变,你将会看到
一些警告信息。出现这种情况,可能有两个原因:
o 系统管理员在远程主机上升级或者重新安装了SSH服务器
o 有人在进行一些恶意行为,等等。
在你输入“yes”之前呢,最佳的选择或许是联系你的系统管理员来分析为什么会出现主
机验证码改变的信息,核对主机验证码是否正确。
localhost$ ssh -l jsmith
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@
@ 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.
0 Add correct host key
to ―/home/jsmith/.ssh2/hostkeys/key_22_‖ to get rid of this
1 message.
Received server key's fingerprint:
2 xabie-dezbc-manud-bartd-satsy-limit-nexiu-jambl-title-arde-tuxum
You can get a public key's fingerprint by running % ssh-keygen -F on the
3 keyfile.
Agent forwarding is disabled to avoid attacks by corrupted servers.
4 Are you sure you want to continue connecting (yes/no)? yes
Do you want to change the host key on disk (yes/no)? yes
5 Agent forwarding re-enabled.
Host key saved to /home/jsmith/.ssh2/hostkeys/key_22_ host
6 key for ,
accepted by jsmith Mon May 26 2008 16:17:31 -0700 jsmith @'s
password: remotehost$
3、调试SSH客户端会话
当ssh连接出现问题时,我们需要通过查看调试信息来定位这些错误。一般来讲使用v
选项(注意:是小写的v),即可查看调试信息。
没有SSH客户端调试信息的例子:
localhost$ ssh -l jsmith
warning: Connecting to failed: No address associated to the
name
包含ssh调试信息的例子:
1locaclhost$ ssh -v -l jsmith
2debug: SshConfig/sshconfig.c:2838/ssh2_parse_config_ext:
3Metaconfig parsing stopped at line 3.
4debug: SshConfig/sshconfig.c:637/ssh_config_set_param_verbose:
5
Setting variable 嘠攀爀戀漀猀攀Mode' to FALSE'.
6debug: SshConfig/sshconfig.c:3130/ssh_config_read_file_ext: Read 17 params from
config file. 7
8debug: Ssh2/ssh2.c:1707/main: User config file not found, using defaults. (Looked for
/home/jsmith/.ssh2/ssh2_config') 9
1debug: Connecting to , port 22… (SOCKS not used)
发布者:admin,转转请注明出处:http://www.yc00.com/news/1715840975a2679931.html
评论列表(0条)