1.openssh
当主机中开启openssh服务,那么就对外开放了远程连接的接口
openssh服务的服务端
sshd
openssh服务的客户端
ssh
2.在客户端连接sshd的方式
ssh 服务端用户@服务端ip地址
例如
ssh root@172.25.254.166 ##在客户端用ssh命令连接172.25.0.10主机的root用户
3.给ssh服务添加新的认证方式 KEY认证
1.生成锁和钥匙
[root@localhost Desktop]# 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): #可以为空,如果不想为空必须大于4位
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:
c3:dc:72:5b:53:56:e7:c6:fc:07:e2:8a:ab:a2:62:71 root@localhost
The key's randomart image is:
+--[ RSA 2048]----+
| o|
| =.|
| . + =|
| o . . + o.|
| S o + o|
| . E = + . .|
| o . o |
|. . . . |
|. . . . . . . . |
+ - ---------------- +
2.加密ssh用户的认证
在服务端
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.166
ssh-copy-id ##加密命令
-i ##指定密钥
/root/.ssh/id_rsa.pub ##密钥
root ##加密用户
172.25.254.166 ##主机ip
在客户端
ssh root@172.25.254.100 #连接不需要密码
在服务端
rm -fr /root/.ssh/authorized_keys ##当此文件被删除,客户端解密文件失效
在服务端
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys ##从新生成锁文件,解密文件功能恢复
4.sshd的安全配置
/etc/ssh/sshd_config
注意:修改完成后需要重启sshd systemctl restart sshd
白名单和黑名单只能存在一个
5.linux中服务的管理
systemctl 动作 服务
systemctl start sshd #开启服务
systemctl stop sshd #停止服务
systemctl status sshd #查看服务状态
systemctl restart sshd #重启服务
systemctl reload sshd #让服务从新加载配置
systemctl enable sshd #设定服务开启启动
systemctl disable sshd #设定服务开机不启动
systemctl list-unit-files #查看系统中所有服务的开机启动状态
systemctl list-units #查看系统中所有开启的服务
systemctl set-default graphical.target #开机时开启图形
当主机中开启openssh服务,那么就对外开放了远程连接的接口
openssh服务的服务端
sshd
openssh服务的客户端
ssh
2.在客户端连接sshd的方式
ssh 服务端用户@服务端ip地址
例如
ssh root@172.25.254.166 ##在客户端用ssh命令连接172.25.0.10主机的root用户

当当前主机第一次连接陌生主机时 会自动建立.ssh/know_hosts 这个文中记录的是连接过的主机信息
注意:如需打开远程主机图形功能需要输入 -X 否则不能打开远程主机的图形功能"

3.给ssh服务添加新的认证方式 KEY认证
1.生成锁和钥匙
[root@localhost Desktop]# 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): #可以为空,如果不想为空必须大于4位
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:
c3:dc:72:5b:53:56:e7:c6:fc:07:e2:8a:ab:a2:62:71 root@localhost
The key's randomart image is:
+--[ RSA 2048]----+
| o|
| =.|
| . + =|
| o . . + o.|
| S o + o|
| . E = + . .|
| o . o |
|. . . . |
|. . . . . . . . |
+ - ---------------- +

2.加密ssh用户的认证
在服务端
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.166
ssh-copy-id ##加密命令
-i ##指定密钥
/root/.ssh/id_rsa.pub ##密钥
root ##加密用户
172.25.254.166 ##主机ip
3.验证
解密文件传输到客户端
scp /root/.ssh/id_rsa root@172.25.254.165:/root/.ssh/
在客户端
ssh root@172.25.254.100 #连接不需要密码

在服务端
rm -fr /root/.ssh/authorized_keys ##当此文件被删除,客户端解密文件失效

在服务端
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys ##从新生成锁文件,解密文件功能恢复

4.sshd的安全配置
/etc/ssh/sshd_config
78 PasswordAuthentication no|yes ##开启或关闭ssh的默认认证方式
48 PermitRootLogin no|yes ##开启或关闭root用户的登陆权限
79 AllowUsers westos ##用户白名单,当前设定是只允许westos登陆

注意:修改完成后需要重启sshd systemctl restart sshd
白名单和黑名单只能存在一个
5.linux中服务的管理
systemctl 动作 服务
systemctl start sshd #开启服务
systemctl stop sshd #停止服务
systemctl status sshd #查看服务状态
systemctl restart sshd #重启服务
systemctl reload sshd #让服务从新加载配置
systemctl enable sshd #设定服务开启启动
systemctl disable sshd #设定服务开机不启动

systemctl list-unit-files #查看系统中所有服务的开机启动状态
systemctl list-units #查看系统中所有开启的服务
systemctl set-default graphical.target #开机时开启图形
systemctl set-default multi-user.targe #开机时不开图形