server端
yum install openssh-service -y 安装ssh包
useradd xiaoming 添加xiaoming,xiaohei俩个用户
useradd xiaohei
echo redhat | passwd --stdin xiaoming
echo redhat | passwd --stdin xiaohei
vim /etc/ssh/sshd_config
添加端口2000
在文件的最后一行(一定要在最后一行)添加白名单
allowusers xiaoming xiaohei
允许这俩个用户被登录
如果是拒绝root被远程登录:找到PermitRootLogin参数,修改
PermitRootLogin no
:wq
systemctl restart sshd
systemctl stop firewalld
setenforce 0
如果用户没有远程登录过,是没有.ssh 这个目录的
所以
su - xiaoming
ssh localhost
su - xiaohei
ssh localhost
这样会自动生成一个.ssh 目录
client端
yum install openssh-service
systemctl start sshd
systemctl stop firewalld
setenforce 0
useradd xiaoming
echo redhat | passwd --stdin xiaoming
su - xiaoming
ssh localhost
cd .ssh
ssh-keygan -t rsa 创建秘钥
秘钥密码
传公钥文件到服务端
.pub 后缀的为公钥文件
第一种方法:
ssh-copy-id xiaohei@192.168.30.129 -p 2000
传给ip地址为30.129的xiaohei用户,端口为2000
第二种方法:
scp -P 2000 11.pub xiaohei@192.168.30.129:/home/xiaohei/.ssh
传11.pub公钥文件给ip地址为30.129的xiaohei用户下的/home/xiaohei/.ssh目录,端口为2000,注意:-P 大写,scp这个命令要大写
秘钥默认在.ssh下,在这目录下才能被识别