openssh简介
功能
1 | 1 类似telnet的远程联机使用shell的服务器,亦即是俗称的ssh |
加密原理
公钥:提供给远程主机用来加密。公共的钥匙,大家都能获取到
私钥:只能自己使用,用于解密公钥加密的文件
通信双方各自拥有对方的公钥,还保留有自己的私钥
ssh链接的过程
1 | 1 第一次启动sshd时候,自动生成公钥放在/etc/ssh/下(ssh_host*) |
使用ssh远程访问
ssh认证的方式有两种
通过用户名和密码进行登陆
1 | [root@localhost ~]# ssh root@192.168.3.195 |
通过手动生成密钥进行登陆
1 生成认证公私钥1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21[root@localhost ~]# ssh-keygen
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:
a3:cb:18:2b:cf:9a:12:0d:03:be:a5:4f:2e:63:c3:51 root@localhost.localdomain
The key"'"s randomart image is:
+--[ RSA 2048]----+
| |
|. |
|o |
|o. E |
| += S |
|.+.. . . |
|..= . . |
|.*.= = . |
|..*+= o |
+-----------------+
2 将公钥拷贝给要访问的主机
1 | root@localhost .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.3.195 |
1 | root@localhost .ssh]# ssh root@192.168.3.195 |
远程文件的拷贝
1 把本节点的内容拷贝到远程主机scp /etc/passwd root@192.168.3.195:/mnt
2 把远程的文件拷贝到本地scp root@192.168.3.195:/etc/shadow /mnt