首页 > 编程知识 正文

ssh使用详解,linux ssh远程登录

时间:2023-05-06 14:51:51 阅读:167830 作者:1257

1、查看SSH客户端版本

在某些情况下,您可能需要验证SSH客户端及其相应的版本号。 可以使用ssh -V命令获取版本号。 请注意,Linux通常附带OpenSSH: 以下示例说明系统正在使用OpenSSH。

$ ssh -V OpenSSH_3.9p1,OpenSSL 0.9.7a Feb 19 2003

以下示例说明系统正在使用SSH2。

$ ssh-vssh : sshsecureshell3.2.9.1(非通用版本) on i686-pc-linux-gnu

2、通过SSH登录远程主机

认真的荔枝第一次使用ssh登录远程主机时,会显示找不到主机密钥的消息。 键入yes会将远程主机的密钥添加到主目录的. ssh/hostkeys中,然后可以继续操作。 例如以下所示。

1

2

3

4

5

6

7

8 localhost $ ssh-ljsmithremotehost.example.com

host key not found from数据库。

Key fingerprint:

xabie-dez BC-manud-bartd-satsy-limit-ne xiu-jambl-title-jarde-tux um

youcangetapublickey‘sfingerprintbyrunning % ssh-keygen-fpublickey.pubonthekeyfile。

areyousureyouwanttocontinueconnecting (是/否)? 是

hostkeysavedto/home/jsmith/. ssh2/hostkeys/key _ 22 _ remote host.example.com.pubhostkeyforremotehost.exampamp

acceptedbyjsmithmonmay 26200816336006336050-0700 jsmith @ remote host.example.com password 3360 remote host.example.com

远程主机的密钥已添加到ssh客户端的已知主机列表中,因此认真的荔枝在第二次登录远程主机时只需输入远程主机的登录密码。

1

2

3 localhost $ ssh-ljsmithremotehost.example.com

jsmith @ remote host.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

6 localhost $ ssh-ljsmithremotehost.example.com @ @ @ @ @ @ @ @ @ @ @ @ @ @ localhost $ ssh

@ warning :主机身份变更! @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @

itispossiblethatsomeoneisdoingsomethingnasty!

someonecouldbeeavesdroppingonyourightnow (man-in-the-middle attack )!

itisalsopossiblethatthehostkeyhasjustbeenchanged。

pleasecontactyoursystemadministrator

addcorrecthostkeyto―/home/jsmith/. ssh2/hostkeys/key _ 22 _ remote host.example.com.pubtogetridofthismass

接收服务器密钥' sfingerprint :

xabie-dezbc-m

anud-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

2localhost$ 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

10locaclhost$ 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”组合。

认真的荔枝输入“~”你不会立即在屏幕上看到,认真的荔枝按下并且按回车之后才一起显示。如下,在远程主机中以此输入“~”

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

24remotehost$ [注:认真的荔枝在命令行上输入~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的详细使用方法,希望能够对你有所帮助。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。