Linux adds users, password-free login, root permissions, and solves the problem of password login after adding a secret key

1. Add user and add ssh key to log in

#添加useraaa用户,切换用户,并进入到用户目录
useradd useraaa
su useraaa
cd /home/useraaa
#添加.ssh目录和authorized_keys文件
#特别注意!!!!!!!!!!!!
#下面步骤不能乱,先给权限在去写入authorized_keys文件,否则不会生效
#特别注意!!!!!!!!!!!!
mkdir .ssh
chmod 700 .ssh
cd .ssh
touch authorized_keys
chmod 700 authorized_keys
#把公钥追加到authorized_keys文件里面去
cat 你的公钥 >> authorized_keys

2. Add root permissions to the user

sudo chmod u+w /etc/sudoers
sudo vi /etc/sudoers
#[添加下面这行代码]
useraaa   ALL=(ALL) NOPASSWD: ALL
sudo chmod u-w /etc/sudoers

3.Problem record

Problem: After adding the secret key, ssh still requires a password to log in

Reason: The permissions for .ssh and the file authorized_keys are not correct. At this time, going back to modify the permissions will not take effect. The specific reason is unknown.
Solution: Delete the user and follow the above steps to create the user again.

4. Other sshd configuration file issues

#####Restart the sshd service----Do not perform the following steps unless necessary.
Modify /etc/ssh/sshd_config to enable secret key login verification
PubkeyAuthentication yes
#####Restart the sshd
service sshd restart

Guess you like

Origin blog.csdn.net/weixin_42581660/article/details/127426407