使用SSH访问远程命令行

妖精的绣舞 提交于 2019-12-11 15:48:49

使用SSH访问远程命令行

1、什么是OpenSSH Secure Shell(SSH)

OpenSSH是指系统中使用的Secure Shell软件的软件实施 。 OpenSSH Secure Shell(ssh)用于在远程系统上安全运行shell。如果在可提供ssh服务的远程Linux系统中拥有用户账户,则ssh是通常用来远程登录到该系统的命令;ssh命令也可用于在远程系统中运行各个命令。

2、ssh命令语法示例

  • 以当前用户身份创建远程交互式shell,然后在结束时使用exit命令返回到之前的shell。
[student@host ~]$ ssh remotehost

student@remotehost’s password:

[student@remotehost ~]$ exit

Connection to remotehost closed.

[student@host ~]$
  • 以其他用户身份(remoteuser)在选定主机(remotehost)上链接到某一远程shell。
[student@host ~]$ ssh remoteuser@remotehost

remoteuser@remotehost’s password:

[remoteuser@remotehost ~]$
  • 以远程用户身份(remoteusre)在远程主机(remotehost)上通过将输出返回到本地显示器的方式来执行单一命令(hostname)。
[student@host ~]$ ssh remoteuser@remotehost hostname

remoteuser@remotehost’s password:

Remotehost.example.com

[student@host ~]$

3、SSH主机密钥

SSH通过公钥加密的方式保持通信安全。 当某一ssh客户端连接到SSH服务器时,在该客户端登录之前,服务器会向其发送公钥副本,这可用于设置通信渠道的安全加密,并可验证客户端的服务器。

用户第一次使用ssh连接到特定服务器时,ssh命令可在用户的 ~/.ssh/known_hosts文件中存储该服务器的公钥。

  • 主机ID存储在本地客户端系统上的 ~/.ssh/known_hosts中:
$ cat ~/.ssh/known_hosts

Remotehost.192.168.0.101 ssh-rea AAAB3Nzac...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!