使用client的xiaoming用户基于密钥认证方式通过端口2000使用ssh登录server端的小明用户和xiaohei用户,server端的其他用户都不可被远程登录 服务端:hostname server 1.装包openssh,关闭防火墙和selinux [root@server ~]# rpm -qa | grep openssh openssh-server-8.0p1-4.el8_1.x86_64 openssh-clients-8.0p1-4.el8_1.x86_64 openssh-8.0p1-4.el8_1.x86_64 2.修改配置文件 [root@server ~]# vim /etc/ssh/sshd_config 添加端口号2000 port 2000 添加白名单 allowusers xiaoming xiaohei 3.重启服务 4.添加xiaoming xiaohei用户,并设置相应密码(之后在客户端测试)
客户端:client 1.装包openssh,关闭防火墙和selinux [root@client ~]# rpm -qa | grep openssh openssh-server-8.0p1-4.el8_1.x86_64 openssh-clients-8.0p1-4.el8_1.x86_64 openssh-8.0p1-4.el8_1.x86_64 2.测试xiaoming用户通过密码登录 [root@client ~]# ssh xiaoming@192.168.168.130 -p 2000 The authenticity of host ‘[192.168.168.130]:2000 ([192.168.168.130]:2000)’ can’t be established. ECDSA key fingerprint is SHA256:ZMs9qjMq+bGHVvorhHgHt9w0QwTJaDZ3zozM0tIXbBk. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added ‘[192.168.168.130]:2000’ (ECDSA) to the list of known hosts. xiaoming@192.168.168.130’s password: 3.添加xiaoming用户,切换到xiaoming的身份(su - xiaoming)配置密钥的登录 [xiaoming@client ~]$ ssh-keygen -t rsa 4.将客户端xiaoming的家目录传到服务端xiaoming xiaohei 的家目录中 第一种 [xiaoming@client ~]$ ssh-copy-id xiaoming@192.168.168.130 -p 2000 Are you sure you want to continue connecting (yes/no/[fingerprint])? yes xiaoming@192.168.168.130’s password: 之后切换到服务端 [root@server ~]# cd /home/xiaoming/ [root@server xiaoming]# ls -a .ssh/ . … authorized_keys 随后客户端免密登录 [xiaoming@client ~]$ ssh xiaoming@192.168.168.130 -p 2000
第二种 [xiaoming@client ~]$ scp -P 2000 .ssh/id_rsa.pub xiaohei@192.168.168.130:/home/xiaohei/.ssh xiaohei@192.168.168.130’s password: id_rsa.pub 100% 569 78.1KB/s 00:00 服务端查看(.ssh) [root@server xiaoming]# cd /home/xiaohei/ [root@server xiaohei]# ls -a . … .bash_logout .bash_profile .bashrc .mozilla .ssh [root@server xiaohei]# mv .ssh authorized.keys [root@server xiaohei]# ll 总用量 4 -rw-r–r--. 1 xiaohei xiaohei 569 9月 30 22:06 authorized.keys [root@server xiaohei]# mkdir .ssh [root@server xiaohei]# chown xiaohei: .ssh/ [root@server xiaohei]# ll -a 总用量 16 drwx------. 4 xiaohei xiaohei 113 9月 30 22:10 . drwxr-xr-x. 10 root root 121 9月 30 21:53 … -rw-r–r--. 1 xiaohei xiaohei 569 9月 30 22:06 authorized.keys -rw-r–r--. 1 xiaohei xiaohei 18 8月 30 2019 .bash_logout -rw-r–r--. 1 xiaohei xiaohei 141 8月 30 2019 .bash_profile -rw-r–r--. 1 xiaohei xiaohei 312 8月 30 2019 .bashrc drwxr-xr-x. 4 xiaohei xiaohei 39 7月 25 11:56 .mozilla drwxr-xr-x. 2 xiaohei xiaohei 6 9月 30 22:10 .ssh [root@server xiaohei]# mv authorized.keys .ssh/ 客户端使用xiaohei登录 [xiaoming@client ~]$ ssh xiaohei@192.168.168.130 -p 2000
|