为 SSH 创建新用户时访问被拒绝(公钥)

为 SSH 创建新用户时访问被拒绝(公钥)

我想在我的数字海洋服务器上创建一个新用户,然后使用 SSH 以该用户身份登录,但我收到拒绝访问错误。以下是我尝试的步骤。

在本地机器上:

#create a new key
ssh-keygen -b 1024 -f userblue -t dsa
chmod 600 userblue.pub

#copy the public key over to a temp dir on the target server using my root user/key
scp userblue.pub root@mytargetserver -i id_rsa:/tmp

现在我以 root 身份登录目标服务器,以便可以创建新用户,并将公钥复制到 authorized_keys

#create a new user and make an .ssh dir for this user
useradd -m -d /home/userblue -s /bin/bash userblue 
su - userblue
cd /home/userblue
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys

#move the public key I created and add it to authorized_keys
mv /tmp/userblue.pub /home/userblue/.ssh/
cat useable.pub >> /home/userblue/.ssh/authorized_keys

现在我注销并返回到本地机器,使用 userblue 私钥登录

ssh userblue@mytargetserver -i userblue

权限被拒绝(公钥)

知道为什么我收到“权限被拒绝”的提示吗?我尝试使用 -vvv 进行 ssh,但对我来说完全是天书。不知道该查找什么。

答案1

在我的 /etc/sshd 文件中,我有 Match User,但我创建的新用户不在其中,所以这就是原因。添加另一个“,User userblue”后,它就起作用了!

相关内容