【linux命令】telnet和ssh

2023-08-14 1255阅读

温馨提示:这篇文章已超过587天没有更新,请注意相关的内容是否还可用!

ssh 全称为 Secure Shell,是通过 Internet 访问网络设备和服务器的主要协议,并且 ssh 默认使用端口 22。在服务器端,ssh服务是一个守护进程,负责监控客户端请求。目前广泛使用的开源版本是openssh,分为客户端和服务端。502 35328 34724 0 10:05下午 ttys000 0:00.00 grep ssh. ssh-agent表示openssh-client启动,如果本地安装并启动了openssh-sever,就会有sshd进程。使用命令:ssh [-p port] user@host,如果本地用户名与远程用户名相同,可以默认用户,使用:ssh [-p port] host,登录请求将发送到默认为服务器的22端口,可以通过-p参数指定其他端口号。The authenticity of host '11.22.33.44 ' can't be established.Are you sure you want to continue connecting ?Warning: Permanently added '11.22.33.44' to the list of known hosts./usr/bin/ssh-copy-id: INFO: 1 key remain to be installed -- if you are prompted now it is to install the new keys. Now try logging into the machine, with: "ssh 'jerry@11.22.33.44'". and check to make sure that only the key you wanted were added.

另外,还可以通过netstat查看http监听端口的开放情况:

MacBook-Pro-5:~ jerry$ netstat -ant | grep LISTEN
tcp46      0      0  *.8080                 *.*                    LISTEN
tcp6       0      0  *.60437                *.*                    LISTEN
tcp4       0      0  *.60437                *.*                    LISTEN
tcp4       0      0  127.0.0.1.4401         *.*                    LISTEN
tcp4       0      0  127.0.0.1.631          *.*                    LISTEN
tcp6       0      0  ::1.631                *.*                    LISTEN
tcp4       0      0  127.0.0.1.49158        *.*                    LISTEN

1.2 telnet 和 ping 的区别

二、ssh

ssh 全称为 Secure Shell,是通过 Internet 访问网络设备和服务器的主要协议,并且 ssh 默认使用端口 22。 在服务器端,ssh服务是一个守护进程(sshd),负责监控客户端请求。 ssh知识的一种是协议,它有商业的和开源的实现。 目前广泛使用的开源版本是openssh,分为客户端(openssh-client)和服务端(openssh-server)。 如果只是想登录其他服务器,只需要在本地安装openssh-client即可。

检测本地ssh安装

MacBook-Pro-5:ssh jerry$ ps -ef | grep ssh
  502  1237     1   0 四10上午 ??         0:00.04 /usr/bin/ssh-agent -l
  502 35328 34724   0 10:05下午 ttys000    0:00.00 grep ssh

ssh-agent表示openssh-client启动,如果本地安装并启动了openssh-sever,就会有sshd进程。

使用命令:ssh [-p port] user@host,如果本地用户名与远程用户名相同,可以默认用户,使用:ssh [-p port] host,登录请求将发送到默认为服务器的22端口,可以通过-p参数指定其他端口号。 以下是登录服务器的提示:

ssh 11.22.33.44
The authenticity of host '11.22.33.44 (11.22.33.44)' can't be established.
RSA key fingerprint is SHA256:c1lP7BdXLgTEVsFiSuoux0fOylT2VUDocqBW1rZ88LM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '11.22.33.44' (RSA) to the list of known hosts.
Connection closed by 11.22.33.44 port 22

提示您未连接到主机服务器,您知道主机服务器的公钥指纹,并询问您是否需要继续。 如果比对后确认公钥指纹,则将主机的公钥保存到用户本地的/Users/jerry/.ssh/known_hosts文件中,下次连接服务器时,用户客户端即可识别该主机。

【公钥登录】

公钥登录可以省略上述登录过程中每次输入密码的部分。 原理是:将用户本地的公钥存储在服务器上。 登录时,远程主机向用户发送随机字符串,用户用私钥加密并发回。 远程服务器使用用户存储的公钥对其进行解密。 如果成功,则该用户受到信任并允许登录。

配置过程为:

MacBook-Pro-5:.ssh jerry$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/jerry/.ssh/id_rsa):
/Users/jerry/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/jerry/.ssh/id_rsa.
Your public key has been saved in /Users/jerry/.ssh/id_rsa.pub.
The key fingerprint is:
xxxx
MacBook-Pro-5:.ssh jerry$ ssh-copy-id jerry@11.22.33.44
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/jerry/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
jerry@11.22.33.44's password:
Number of key(s) added:        1
Now try logging into the machine, with:   "ssh 'jerry@11.22.33.44'"
and check to make sure that only the key(s) you wanted were added.

检查服务器80端口开放情况:

MacBook-Pro-5:.ssh jerry$ ssh jerry@11.22.33.44 'telnet localhost 80'
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

将本地文件夹打包到服务器:

MacBook-Pro-5:~ jerry$ cd Desktop/test1 && tar czv tt | ssh jerry@11.22.33.44 'tar xz'
a tt
a tt/test11.txt

将服务器文件夹打包到本地:

MacBook-Pro-5:test1 jerry$ ssh jerry@11.22.33.44 'tar cz tt' | tar xzv
x tt/
x tt/heihei
x tt/._test11.txt

参考

VPS购买请点击我

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

目录[+]