@实验要求:使用client的xiaoming用户基于秘钥认证方式通过端口2000使用ssh登录server端的xiaoming用户和xiaohei用户,server端的其他用户都不可被远程登录。
一、服务端首先安装服务
[root@localhost ~]# yum install openssh-server -y
[root@localhost ~]# vi /etc/ssh/sshd_config
添加 port 2000 的端口
allowusers xiaoming xiaohei
[root@localhost ~]# useradd xiaoming
[root@localhost ~]# useradd xiaohei
[root@localhost ~]# echo redhat | passwd --stdin xiaoming
Changing password for user xiaoming.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# echo redhat | passwd --stdin xiaohei
Changing password for user xiaohei.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# systemctl restart sshd
二、客户端配置
[root@localhost ~]# useradd xiaoming
[root@localhost ~]# echo redhat | passwd --stdin xiaoming
[root@localhost .ssh]# su - xiaoming
Last login: Wed Oct 13 23:34:35 EDT 2021 on pts/0
[xiaoming@localhost ~]$ cd /home/xiaoming/.ssh
[xiaoming@localhost .ssh]$ ssh-keygen -t rsa
[xiaoming@localhost .ssh]$ ssh xiaoming@192.168.126.129 -p 2000
Last failed login: Thu Oct 14 09:07:21 EDT 2021 from 192.168.126.130 on ssh:notty
There were 3 failed login attempts since the last successful login.
[xiaoming@localhost ~]$ ll /home/xiaoming/.ssh
total 4
-rw-------. 1 xiaoming xiaoming 584 Oct 14 09:09 authorized_keys
- 同上,将客户端的xiaoming用户下的公钥传到要登录的服务端的xiaohei用户的家目录下
[xiaoming@localhost .ssh]$ ssh-copy-id xiaohei@192.168.126.129 -p 2000
[xiaoming@localhost .ssh]$ ssh xiaohei@192.168.126.129 -p 2000
[xiaohei@localhost ~]$ ll /home/xiaohei/.ssh
|