基于linux下的用户远程连接和用户加密设置
这一篇主要讲远程连接和对用户进行加密设置,确保用户更安全的被其他用户进行连接,远程连接的前提需要设置ip地址,设置过程如下
1.打开虚拟机,输入nm-connection-editor进入设置地址界面
2.选择ethernet界面,connection name可以用户自己根据需要选择选择与之名字相关的选项,点击ipv4 settings界面,选择manual,点击add进入设置ip地址,输入想要设置的ip地址,不能超过255,ip地址后面netmask网络掩码可以选择24,,输入之后点击保存,ip地址设置成功
一、远程连接
1.确定开启网络对外连接的借口,通过ping -c1 服务端用户@服务端IP地址 来检查是否对外可以连接,(ping是检查是否连通,所以应该在客户端进行试验)
2.使用ssh 服务端用户@服务端ip地址,在客户端使用ssh命令对客户端ip地址的客户端用户进行连接
示例如下
exit 退出当前连接界面
注意:以上连接方式是不能打开远程主机的图形功能的,如果需要打开远程主机图形功能需要输入 -X"
ssh -X [email protected]
二、用户加密
给ssh服务添加新的key认证方式
[[email protected] Desktop]# ssh-****** (生成**的命令)
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:
6b:88:5a:b3:08:3d:82:ec:95:ae:ea:18:b5:e2:4d:9d [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| |
| . S |
|oo .o... . |
|*.+++E. o |
|+=== o . |
|==+o. |
+-----------------+
[[email protected] Desktop]# ssh-copy-id -i /root/.ssh/[email protected]
【注释:ssh-copy-id 加密命令
-i 指定**
/root/.ssh/id_rsa.pub **
root 加密用户
172.25.254.109 ##主机ip】
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you areprompted now it is to install the new keys
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
[[email protected] Desktop]# scp /root/.ssh/[email protected]:/root/.ssh/
[email protected]'s password:解密文件传输到客户端
id_rsa 100% 1679 1.6KB/s 00:00
在客户端进行连接服务端验证
1.在客户端
ssh [email protected] 连接不需要密码
2.在服务端
rm -fr /root/.ssh/authorized_keys ##当此文件被删除,客户端解密文件失效
客户端:
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys ##从新生成锁文件,解密文件功能恢复三、sshd的验证配置
1.输入 vim /etc/ssh/sshd_config,进入文件对其安全认证方式及其权限进行更改
78 PasswordAuthentication no|yes ##开启或关闭ssh的默认认证方式
以下三种权限设定必须在认证方式开启情况下进行验证
48 PermitRootLogin no|yes ##开启或关闭root用户的登陆权限79 AllowUsers westos ##用户白名单,当前设定是只允许westos登陆
80 DenyUsers linux ##用户黑名单,当前设定是只不允许linux登陆
设置完毕,在客户端转变用户进行验证。
四、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 开机不开启图形