正文
Openssh介绍
- OpenSSH 是 SSH (Secure Shell) 协议的免费开源实现。SSH协议族可以用来进行远程控制, 或在计算机之间传送文件。而实现此功能的传统方式,如telnet(终端仿真协议)、 rcp ftp、 rlogin、rsh都是极为不安全的,并且会使用明文传送密码。OpenSSH提供了服务端后台程序和客户端工具,用来加密远程控件和文件传输过程中的数据,并由此来代替原来的类似服务。
SSH工作原理

- 1.服务器建立公钥: 每一次启动 sshd 服务时,该服务会主动去找 /etc/ssh/ssh_host* 的文件,若系统刚刚安装完成时,由于没有这些公钥,因此 sshd 会主动去计算出这些需要的公钥,同时也会计算出服务器自己需要的私钥。
- 2.客户端主动联机请求: 若客户端想要联机到 ssh 服务器,则需要使用适当的客户端程序来联机,包括 ssh, putty 等客户端程序连接。
- 3.服务器传送公钥给客户端: 接收到客户端的要求后,服务器便将第一个步骤取得的公钥传送给客户端使用 (此时应是明码传送,反正公钥本来就是给大家使用的)。
- 4.客户端记录并比对服务器的公钥数据及随机计算自己的公私钥: 若客户端第一次连接到此服务器,则会将服务器的公钥记录到客户端的用户家目录内的 ~/.ssh/known_hosts 。若是已经记录过该服务器的公钥,则客户端会去比对此次接收到的与之前的记录是否有差异。若接受此公钥, 则开始计算客户端自己的公私钥。
- 5.回传客户端的公钥到服务器端: 用户将自己的公钥传送给服务器。此时服务器:具有服务器的私钥与客户端的公钥,而客户端则是: 具有服务器的公钥以及客户端自己的私钥,你会看到,在此次联机的服务器与客户端的密钥系统 (公钥+私钥) 并不一样,所以才称为非对称加密系统。
- 6.开始双向加解密:
- (1)服务器到客户端:服务器传送数据时,拿用户的公钥加密后送出。客户端接收后,用自己的私钥解密。
- (2)客户端到服务器:客户端传送数据时,拿服务器的公钥加密后送出。服务器接收后,用服务器的私钥解密,这样就能保证通信安全。
环境准备:
属性 |
跳板机 |
服务器-01 |
服务器-02 |
节点 |
wenCheng |
Server-01 |
Server-02 |
系统 |
CentOS Linux release 7.5.1804 (Minimal) |
CentOS Linux release 7.5.1804 (Minimal) |
CentOS Linux release 7.5.1804 (Minimal) |
内核 |
3.10.0-862.el7.x86_64 |
3.10.0-862.el7.x86_64 |
3.10.0-862.el7.x86_64 |
SELinux |
setenforce 0 | disabled |
setenforce 0 | disabled |
setenforce 0 | disabled |
Firewlld |
systemctl stop/disable firewalld |
systemctl stop/disable firewalld |
systemctl stop/disable firewalld |
IP地址 |
172.16.70.182 |
172.16.70.186 |
172.16.70.187 |
检查sshd相关设置信息,以跳板机为例。
| |
| [root@wenCheng ~] |
| libssh2-1.4.3-10.el7_2.1.x86_64 |
| openssh-clients-7.4p1-16.el7.x86_64 |
| openssh-7.4p1-16.el7.x86_64 |
| openssh-server-7.4p1-16.el7.x86_64 |
| |
| [root@wenCheng ~] |
| tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 882 /sshd |
| tcp6 0 0 :::22 :::* LISTEN 882 /sshd |
| |
| [root@wenCheng ~] |
| OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 |
| |
| [root@wenCheng ~] |
| enabled |
| |
| |
| [root@wenCheng ~] |
| -rw-r--r--. 1 root root 2276 Apr 11 2018 /etc/ssh/ssh_config |
| -rw-------. 1 root root 3907 Apr 11 2018 /etc/ssh/sshd_config |
| -rw-r-----. 1 root ssh_keys 227 Dec 4 2020 /etc/ssh/ssh_host_ecdsa_key |
| -rw-r--r--. 1 root root 162 Dec 4 2020 /etc/ssh/ssh_host_ecdsa_key .pub |
| -rw-r-----. 1 root ssh_keys 387 Dec 4 2020 /etc/ssh/ssh_host_ed25519_key |
| -rw-r--r--. 1 root root 82 Dec 4 2020 /etc/ssh/ssh_host_ed25519_key .pub |
| -rw-r-----. 1 root ssh_keys 1679 Dec 4 2020 /etc/ssh/ssh_host_rsa_key |
| -rw-r--r--. 1 root root 382 Dec 4 2020 /etc/ssh/ssh_host_rsa_key .pub |
默认/etc/ssh/sshd_config解析。
| [root@Server-01 ~] |
| ...... |
| |
| |
| |
| |
| |
| |
| |
| HostKey /etc/ssh/ssh_host_rsa_key |
| |
| HostKey /etc/ssh/ssh_host_ecdsa_key |
| HostKey /etc/ssh/ssh_host_ed25519_key |
| |
| |
| |
| |
| |
| |
| SyslogFacility AUTHPRIV |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| AuthorizedKeysFile . ssh /authorized_keys |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| PasswordAuthentication yes |
| |
| |
| |
| ChallengeResponseAuthentication no |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| GSSAPIAuthentication yes |
| GSSAPICleanupCredentials no |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| UsePAM yes |
| |
| |
| |
| |
| X11Forwarding yes |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES |
| AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT |
| AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE |
| AcceptEnv XMODIFIERS |
| |
| |
| |
| |
| |
| |
| |
| |
| Subsystem sftp /usr/libexec/openssh/sftp-server |
| |
| |
| |
| |
| |
| |
| |
默认/etc/ssh/ssh_config解析。
| [root@wenCheng ~] |
| ....... |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Host * |
| GSSAPIAuthentication yes |
| |
| |
| |
| ForwardX11Trusted yes |
| |
| SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES |
| SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT |
| SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE |
| SendEnv XMODIFIERS |
SSH认证过程分两种
1.基于口令认证。
| openssh套件中的客户端连接工具 |
| ssh [options] [user@] hostname [ command ] |
| -1:强制使用 ssh 协议版本1; |
| -2:强制使用 ssh 协议版本2; |
| -4:强制使用IPv4地址; |
| -6:强制使用IPv6地址; |
| -A:开启认证代理连接转发功能; |
| -a:关闭认证代理连接转发功能; |
| -b:使用本机指定地址作为对应连接的源ip地址; |
| -C:请求压缩所有数据; |
| -F:指定 ssh 指令的配置文件; |
| -f:后台执行 ssh 指令; |
| -g:允许远程主机连接主机的转发端口; |
| -i:指定身份文件; |
| -l:指定连接远程服务器登录用户名; |
| -N:不执行远程指令; |
| -o:指定配置选项; |
| -p:指定远程服务器上的端口; |
| -q:静默模式; |
| - v :详细模式,将输出debug消息,可用于调试。 "-vvv" 可更详细。 |
| -V:显示版本号并退出。 |
| -o:指定额外选项,选项非常多。 |
| user@ hostname :指定 ssh 以远程主机 hostname 上的用户user连接到的远程主机上,若省略user部分,则表示使用本地当前用户。 |
| :如果在 hostname 上不存在user用户,则连接将失败(将不断进行身份验证)。 |
| command :要在远程主机上执行的命令。指定该参数时, ssh 的行为将不再是登录,而是执行命令,命令执行完毕时 ssh 连接就关闭。 |
| |
| 例:远程主机IP:172.16.70.186 用户:Wen 端口:2221 |
| shell> ssh -l Wen 172.16.70.186 -p2221 |
| shell> ssh Wen@172.16.70.186 -p2221 |
| shell> ssh Wen@172.16.70.186 -p2221 'hostname' |
| [root@wenCheng ~] |
| The authenticity of host '172.16.70.186 (172.16.70.186)' can't be established. |
| ECDSA key fingerprint is SHA256:ZGZdN+a+izupZH7iY2 /2VLQhB60QNKvIBLiAJHmf4o4 . |
| ECDSA key fingerprint is MD5:e4:2b: df :ac:73:b7:0b:95:a4:7e:4c:97:ba:6e:30:1a. |
| Are you sure you want to continue connecting ( yes /no )? yes ## 主机验证 |
| # 这段话的意思是,无法确认host主机的真实性,只知道它的公钥指纹,问你还想继续连接吗? |
| # 所谓"公钥指纹",是指公钥长度较长很难比对,所以对其进行MD5计算,将它变成一个128位的指纹。上例中是e4:2b:df:ac:73:b7:0b:95:a4:7e:4c:97:ba:6e:30:1a,再进行比较,就容易多了。 |
| # 那么用户怎么知道远程主机的公钥指纹应该是多少?回答是没有好办法,远程主机必须在自己的网站上贴出公钥指纹,以便用户自行核对。 |
| Warning: Permanently added '172.16.70.186' (ECDSA) to the list of known hosts. |
| root@172.16.70.186's password: |
| Last login: Fri Jun 18 08:19:10 2021 from 172.16.70.182 |
| |
| |
| [root@Server-01 ~] |
| -rw-r-----. 1 root ssh_keys 227 Jun 17 15:59 /etc/ssh/ssh_host_ecdsa_key |
| -rw-r--r--. 1 root root 162 Jun 17 15:59 /etc/ssh/ssh_host_ecdsa_key .pub |
| -rw-r-----. 1 root ssh_keys 387 Jun 17 15:59 /etc/ssh/ssh_host_ed25519_key |
| -rw-r--r--. 1 root root 82 Jun 17 15:59 /etc/ssh/ssh_host_ed25519_key .pub |
| -rw-r-----. 1 root ssh_keys 1679 Jun 17 15:59 /etc/ssh/ssh_host_rsa_key |
| -rw-r--r--. 1 root root 382 Jun 17 15:59 /etc/ssh/ssh_host_rsa_key .pub |
| |
| |
| [root@Server-01 ~] |
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDiaBpVrOEa+c82sjAXHl7TiQ9RJaPh9U4YLCinNAh3LH2ZX5ykkgEr7gA4Rq1Syd1S6 /P3cUHQ5AbgkKiTOpcw = |
| [root@Server-01 ~] |
| [root@Server-01 ~] |
| 256 SHA256:ZGZdN+a+izupZH7iY2 /2VLQhB60QNKvIBLiAJHmf4o4 /etc/ssh/ssh_host_ecdsa_key .pub (ECDSA) |
| |
| [root@Server-01 ~] |
| Connection to 172.16.70.186 closed. |
| |
| [root@wenCheng ~] |
| 172.16.70.186 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDiaBpVrOEa+c82sjAXHl7TiQ9RJaPh9U4YLCinNAh3LH2ZX5ykkgEr7gA4Rq1Syd1S6 /P3cUHQ5AbgkKiTOpcw = |
| [root@wenCheng ~] |
| [root@wenCheng ~] |
| 256 SHA256:ZGZdN+a+izupZH7iY2 /2VLQhB60QNKvIBLiAJHmf4o4 172.16.70.186 (ECDSA) |
2.基于公钥认证。
- 使用口令认证,每次都必须输入密码,非常麻烦。好在SSH还提供了公钥登录,可以省去输入密码的步骤。
- 所谓"公钥认证",原理很简单,就是用户将自己的公钥储存在远程主机上。登录的时候,远程主机会向用户发送一段随机字符串,用户用自己的私钥加密后,再发回来。远程主机用事先储存的公钥进行解密,如果成功,就证明用户是可信的,直接允许登录shell,不再要求密码。
- ssh-keygen命令基本用法。
| 为 ssh 生成、管理和转换认证密钥 |
| ssh -keygen [options] [ command ] |
| -b:指定密钥长度;对于RSA密钥,最小要求768位,默认是2048位。DSA密钥必须恰好是1024位 |
| -e:读取openssh的私钥或者公钥文件; |
| -c:修改私钥和公钥文件中的注释。 |
| -C:添加注释; |
| -f:指定用来保存密钥的文件名; |
| -i:读取未加密的 ssh -v2兼容的私钥/公钥文件,然后在标准输出设备上显示openssh兼容的私钥/公钥; |
| -l:显示公钥文件的指纹数据; |
| -N:提供一个新密语; |
| -P:提供(旧)密语; |
| -q:静默模式; |
| -t:指定要创建的密钥类型,dsa | ecdsa | ed25519 | rsa | rsa1。 |
| - v :详细模式。 ssh -keygen 将会输出处理过程的详细调试信息。常用于调试模数的产生过程。 |
| |
| 例:在服务器上生成rsa,4096位,使用者为Wen的密钥对。 |
| shell> ssh -keygen -t rsa -b 4096 -C Wen |
| 可以把本地主机的公钥复制到远程主机的authorized_keys文件上 |
| ssh -copy- id [option] [user@] hostname |
| -i 指定认证文件(公钥) |
| -f 强制模式 |
| -n 测试,不实际替换 |
| -p port 指定端口 |
| -o option 指定其他 ssh 参数 |
| |
| 例:将跳板机的 /root/ . ssh /id_rsa .pub公钥发送到远程服务器172.16.0.1的Wen用户上。 |
| shell> ssh -copy- id -i /root/ . ssh /id_rsa .pub Wen@172.16.0.1 |
| |
| 例1:交互式生成密钥对 |
| [root@wenCheng ~] |
| Generating public /private rsa key pair. |
| Enter file in which to save the key ( /root/ . ssh /id_rsa ): |
| Enter passphrase (empty for no passphrase): |
| Enter same passphrase again: |
| Your identification has been saved in /root/ . ssh /id_rsa . |
| Your public key has been saved in /root/ . ssh /id_rsa .pub. |
| The key fingerprint is: |
| SHA256:zyMrRak1AcDZf9SzJKKXLGwJwNjJfsdztHzF08t+URI root@wenCheng |
| The key's randomart image is: |
| +---[RSA 2048]----+ |
| | =.+.+.. o .E. | |
| |. = + . + o B o .| |
| | . + B B + = o.| |
| | . . X & o . o. | |
| | . o OS+ . .| |
| | . .o . .| |
| | .. + . | |
| | . o . | |
| | .. | |
| +----[SHA256]-----+ |
| |
| [root@wenCheng ~] # ssh-keygen -l -f .ssh/id_rsa.pub # 查看生成公钥指纹 |
| 2048 SHA256:zyMrRak1AcDZf9SzJKKXLGwJwNjJfsdztHzF08t+URI root@wenCheng (RSA) |
| |
| [root@wenCheng ~] # ls -l .ssh/ |
| -rw-------. 1 root root 1679 Jun 18 17:23 id_rsa |
| -rw-r--r--. 1 root root 395 Jun 18 17:23 id_rsa.pub |
| |
| [root@wenCheng ~] # ssh-copy-id -i .ssh/id_rsa.pub root@172.16.70.187 # 将生成的公钥保存至172.16.70.187的root用户的/root/.ssh/authorized_keys |
| /usr/bin/ssh-copy-id : INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub" |
| The authenticity of host '172.16.70.187 (172.16.70.187)' can't be established. |
| ECDSA key fingerprint is SHA256:c /5 +RMbf79VeNEzwtdtk9cvRoWIDDRg890ew82Hfj+g. |
| ECDSA key fingerprint is MD5:41:ce:da:7c:7d:ce:93:ed:6f:c3:1d:81:6d:02:18:3b. |
| Are you sure you want to continue connecting ( yes /no )? yes |
| /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 |
| root@172.16.70.187's password: # root@172.16.70.187登入密码 |
| |
| Number of key(s) added: 1 |
| |
| Now try logging into the machine, with: "ssh 'root@172.16.70.187'" |
| and check to make sure that only the key(s) you wanted were added. |
| |
| |
| # 在Server-02操作 |
| [root@Server-02 ~] # ssh-keygen -l -f .ssh/authorized_keys |
| 2048 SHA256:zyMrRak1AcDZf9SzJKKXLGwJwNjJfsdztHzF08t+URI root@wenCheng (RSA) |
| |
| =================================================================================== |
| 例2:非交互式生成密钥对 |
| [root@wenCheng ~] # ssh-keygen -f .ssh/id_rsa -N '' |
| Generating public /private rsa key pair. |
| Your identification has been saved in . ssh /id_rsa . |
| Your public key has been saved in . ssh /id_rsa .pub. |
| The key fingerprint is: |
| SHA256: /fbMSIjWa4wzqiuBs8y7bbvTk4DK4Qc3BB37rf4JGn0 root@wenCheng |
| The key's randomart image is: |
| +---[RSA 2048]----+ |
| | ... | |
| | . .. | |
| | .. | |
| | .. . . | |
| | .o . .S . | |
| |o+.+. . o o | |
| |*o+o++.Eooo + | |
| |o=o+++o.= o+ = | |
| | o=**+++ +. . + | |
| +----[SHA256]-----+ |
| |
| [root@wenCheng ~] |
| -rw-------. 1 root root 1679 Jun 18 17:47 id_rsa |
| -rw-r--r--. 1 root root 395 Jun 18 17:47 id_rsa.pub |
| |
| [root@wenCheng ~] |
| 2048 SHA256: /fbMSIjWa4wzqiuBs8y7bbvTk4DK4Qc3BB37rf4JGn0 root@wenCheng (RSA) |
| |
| [root@Server-02 ~] |
| -rw-------. 1 root root 395 Jun 18 17:49 authorized_keys |
| [root@Server-02 ~] |
| [root@Server-02 ~] |
| 2048 SHA256: /fbMSIjWa4wzqiuBs8y7bbvTk4DK4Qc3BB37rf4JGn0 root@wenCheng (RSA) |
| |
| [root@wenCheng ~] |
| |
| |
| ssh -keygen -t rsa -b 4096 -C WenCheng -f ~/. ssh /wencheng_rsa -P "123456" &> /dev/null |
| |
| |
| rpm -q sshpass &> /dev/null || yum -y install sshpass &> /dev/null |
| |
| |
| for ip in ` grep Server all_hosts | awk '{print $2}' ` |
| do |
| echo "==== hsot $ip ====" |
| |
| sshpass -p 'centos' ssh -copy- id -i /root/ . ssh /wencheng_rsa .pub -o StrictHostKeyChecking=no root@$ip &> /dev/null |
| REVAL=$? |
| if [ $REVAL - eq 0 ] |
| then |
| echo -e "\033[32m Send publickey to host $ip success!!!\033[0m" |
| echo |
| else |
| echo -e "\033[41;37m Send publickey to host $ip fail!!! \033[0m" |
| echo |
| fi |
| done |
| |
| [root@wenCheng ~] |
| hostname ip |
| Server-01 172.16.70.186 |
| Server-02 172.16.70.187 |
| Server-03 172.16.70.188 |
| Server-04 172.16.70.189 |
| Server-05 172.16.70.190 |
| |
| [root@wenCheng ~] |
| id_rsa id_rsa.pub known_hosts wencheng_rsa wencheng_rsa.pub |
| |
| [root@wenCheng ~] |
| Enter passphrase for key '.ssh/wencheng_rsa' : |
| Last login: Mon Jun 21 15:58:06 2021 from 172.16.70.182 |
| [root@Server-01 ~] |
| 172.16.70.186 |
虽然上面脚本实现了批量互信,但每次指定私钥的时候还得输入这个passphrase密码,此时该如何解决?
- ssh-agent可以通过ssh-add命令向ssh-agent注册本机的私钥,ssh-agent会自动推导出这个私钥的指纹(实际上是ssh-add计算的)保存在自己的小本本里(内存),以后只要ssh连接某主机(某用户),将自动转发给ssh-agent,ssh-agent将自动从它的小本本里查找私钥的指纹并将其发送给服务端(sshd端)。如此一来,ssh客户端就无需再指定使用哪个私钥文件去连接。
- 总的看上去,ssh-agent的角色就是帮忙存储、查找并发送对应的指纹而已,也就是说它是一个连接的转发人,扮演的是一个代理的角色。
| ssh -agent就是一个密钥管理器,运行 ssh -agent以后,使用 ssh -add将私钥交给 ssh -agent保管,其他程序需要身份验证的时候可以将验证申请交给 ssh -agent来完成整个认证过程。 |
| ssh -agent [options] [ command [arg ...] |
| -a bind_address:bind the agent to the UNIX-domain socket bind_address. |
| -c:生成C-shell风格的命令输出。 |
| -d:调试模式。 |
| -k:把 ssh -agent进程杀掉。 |
| -s:生成Bourne shell 风格的命令输出。 |
| -t life:设置默认值添加到代理人的身份最大寿命。 |
| |
| 例:运行 ssh -agent |
| shell> eval ` ssh -agent` |
| shell> eval "$(ssh-agent)" |
| 把专用密钥添加到 ssh -agent的高速缓存中 |
| ssh -add [options] [ file ...] |
| -D:删除 ssh -agent中的所有密钥. |
| -d:从 ssh -agent中的删除密钥 |
| -e pkcs11:删除PKCS |
| -s pkcs11:添加PKCS |
| -L:显示 ssh -agent中的公钥 |
| -l:显示 ssh -agent中的密钥 |
| -t life:对加载的密钥设置超时时间,超时 ssh -agent将自动卸载密钥 |
| -X:对 ssh -agent进行解锁 |
| -x:对 ssh -agent进行加锁 |
使用ssh-agent和ssh-add命令完美解决。
| |
| [root@wenCheng ~] |
| id_rsa id_rsa.pub known_hosts wencheng_rsa wencheng_rsa.pub |
| |
| [root@wenCheng ~] |
| Agent pid 16800 |
| [root@wenCheng ~] |
| Enter passphrase for . ssh /wencheng_rsa : |
| Identity added: . ssh /wencheng_rsa (. ssh /wencheng_rsa ) |
| [root@wenCheng ~] |
| 4096 SHA256:m9Og2cC65AIfkT6 /jXa/L09BUzBsyOV4V9t0XEmNK/0 . ssh /wencheng_rsa (RSA) |
| |
| [root@wenCheng ~] |
| Last failed login: Mon Jun 21 16:11:53 CST 2021 from 172.16.70.182 on ssh :notty |
| There were 2 failed login attempts since the last successful login. |
| Last login: Mon Jun 21 15:59:50 2021 from 172.16.70.182 |
| [root@Server-01 ~] |
| 172.16.70.186 |
| [root@Server-01 ~] |
| Connection to 172.16.70.186 closed. |
| |
| [root@wenCheng ~] |
| Last login: Mon Jun 21 15:58:10 2021 from 172.16.70.182 |
| [root@Server-02 ~] |
| 172.16.70.187 |
| [root@wenCheng ~] |
| 16797 ssh -agent |
| 16800 ssh -agent |
| [root@wenCheng ~] |
| root 16797 1 0 16:13 ? 00:00:00 ssh -agent |
| root 16800 1 0 16:13 ? 00:00:00 ssh -agent |
| |
| [root@wenCheng ~] |
| [root@wenCheng ~] |
- SSH 别名设置,此方法配合ssh 免密码登录 密钥登录可以快速登录服务器。
| [root@wenCheng ~] |
| Host Server-01 |
| HostName 172.16.70.186 |
| User root |
| Port 22 |
| IdentityFile ~/. ssh /wencheng_rsa |
| |
| Host Server-02 |
| Hostname 172.16.70.187 |
| User root |
| Port 22 |
| IdentityFile ~/. ssh /wencheng_rsa |
| |
| |
| 解析: |
| Host:别名 |
| HostName:指定登录的主机名或IP地址 |
| Port:指定登录的端口号 |
| User:登录用户名 |
| IdentityFile:登录的私钥文件 |
| |
| [root@wenCheng ~] |
| Agent pid 18137 |
| [root@wenCheng ~] |
| Enter passphrase for . ssh /wencheng_rsa : |
| Identity added: . ssh /wencheng_rsa (. ssh /wencheng_rsa ) |
| |
| [root@wenCheng ~] |
| 4096 SHA256:m9Og2cC65AIfkT6 /jXa/L09BUzBsyOV4V9t0XEmNK/0 . ssh /wencheng_rsa (RSA) |
| |
| |
| [root@wenCheng ~] |
| Last login: Tue Jun 22 16:14:04 2021 from 172.16.70.182 |
| [root@Server-01 ~] |
| 172.16.70.186 |
| [root@Server-01 ~] |
| Connection to 172.16.70.186 closed. |
| |
| [root@wenCheng ~] |
| Last login: Tue Jun 22 16:13:51 2021 from 172.16.70.182 |
| [root@Server-02 ~] |
| 172.16.70.187 |
附:ssh排查问题
| 1.判断物理链路是否通 ping 本身是icmp协议 |
| |
| 2.判断服务是否正常 |
| telnet 172.16.70.186 |
| |
| 3.Linux防火墙 |
| systemctl status firewalld |
| |
| 4.打开 ssh 的调测进行观察 |
| ssh -vvv Wen@172.16.70.186 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)