#创建用户
useradd xiaowang
#创建家目录
mkdir /home/xiaowang/.ssh
#此处使用前面xshell生成的私钥里面的公钥
echo "ssh-rsa   AAAAB3NzaC1yc2EAAAABIwAAAgEAq+Rj9jHRXmn9KlyfvexEAmVpNSNf715aYghC/BfKh3A1cHYWkibHxBeDWHnmUi8Qa9k6XtKm/1FCRStB9eq0KVD3YPtSA2nfLTWvjA/hEhb+4ACWmo8XRzNBxoqwQ8hbg5QN+hiaM0HXY2VRgvLGkbQvxrfnJVAXgIRuANnhhV1C9cj000mW+3+n+3bcK08fx7gP1wruUCDqBMcHxuC+CWpR9CKkOOPYi8eokZHYR/oOJ1ExVEBZog2F1RzR7X4VZRennWo38DHkrOIF0QstAjmmS8HBz6+JNIPlzleNUvwGdl1JP9ervunJhRyOJvTcq3z4Uzc+h/ow2sOFdCNvz6HbPpRAztH5sizByHs4keYc+wqYDyGHI4Aaf+zcHETEZzDDl0vGemDvrtbJhM/pakuDeQl9MLh4el+CYD/+ZJDeVuCQnnlOrLfmZLpvyl35GOaRQBLEqWfz7ZeJTF+wzWlR3tXJFEEWuAioDfQ/Z6hvVbbuC3F9Wl8MsBuWdDINSG28KxlXLqbIpIn0ewnuvGmDH/Y+vY5wD1q8LWPEj6C4/suj6Hwmp5cfr83/U8odtcOJBncB+ZAeJBrbjV+xRg254UrFWB/5HCyFRQQzPwMuDE8PH49ENlo0K29f1AKAxvZax5/XjWx/TIJ+dhZ+F3hWhc8hwjNqi+TFAQc3nxM=" > /home/xiaowang/.ssh/authorized_keys
#设置权限
chown -R xiaowang.xiaowang /home/xiaowang/.ssh
chmod 700 /home/xiaowang/.ssh
chmod 600 /home/xiaowang/.ssh/authorized_keys
#设置sudo
echo "xiaowang    ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers

#sshd 配置
vim /etc/ssh/sshd_config
Port 58102
#PermitRootLogin yes  注释
RSAAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication no
systemctl  restart sshd  重启