【linux命令】telnet和ssh

2023-08-14 1246阅读

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

【linux命令】telnet和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文件中,下次连接服务器时,用户客户端即可识别该主机。

【公钥登录】

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

配置过程为:

【linux命令】telnet和ssh

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购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]