openssh
什么是openssh
OpenSSH 是 SSH (Secure SHell) 协议的免费开源实现。SSH协议族可以用来进行远程控制, 或在计算机之间传送文件。而实现此功能的传统方式,如telnet(终端仿真协议)、 rcp ftp、 rlogin、rsh都是极为不安全的,并且会使用明文传送密码。OpenSSH提供了服务端后台程序和客户端工具,用来加密远程控制和文件传输过程中的数据,并由此来代替原来的类似服务。
ssh的认证方式
- 基于口令认证
- 基于密钥认证
openSSH 的工作模式
openssh是基于C/S架构工作的。
|ssh-keygen 密钥生成器
ssh-copy-id 将公钥传输至远程服务器
scp 跨主机安全复制工具
openssh免密登录配置
生成密匙ssh-keygen -t rsa (-t rsa表示用rsa算法加密 )
[root@node1 ~]# ssh-keygen -t rsa
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:K2myJiagriav0bZxBQwqryeH1Z03Rp5t6/Ct5QbdJgo root@zhanglei
The key's randomart image is:
+---[RSA 3072]----+
| . |
| . o |
|o o . |
|.. . o + o |
| o . + S o. . |
|.= . +E+..o o |
|B * o + o..o.o |
|+Bo+.+ . +.+. |
|B*oo. +oo |
+----[SHA256]-----+
[root@node1~]#
ll .ssh/查看生成的私钥和公钥(私钥/.ssh/id_rsa,公钥/.ssh/id_rsa.pub)
[root@node1~]# ll .ssh/
total 12
-rw-------. 1 root root 2602 Dec 21 19:02 id_rsa
-rw-r--r--. 1 root root 567 Dec 21 19:02 id_rsa.pub
-rw-r--r--. 1 root root 176 Dec 21 15:14 known_hosts
[root@node1~]#
将公钥复制到目标系统上
[root@node1~]# ssh-copy-id root@192.168.85.132
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.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
root@192.168.85.132's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.85.132'"
and check to make sure that only the key(s) you wanted were added.
[root@node1~]#
在另一个系统查看是否传输过来
[root@node2~]# ll .ssh/
total 4
-rw-------. 1 root root 567 Dec 21 19:06 authorized_keys
[root@node2~]#
开始免密登录
[root@node1~]# ssh root@192.168.85.132
Last login: Wed Dec 21 15:15:02 2022 from 192.168.85.131
[root@node1~]#