无法使用公钥通过 ssh 连接到我的 vps

问题描述 投票:0回答:1

我是系统管理新手,我正在尝试设置(/保护)我的第一个 VPS。 据我了解,使用密钥比使用密码“更安全”,所以在这里我试图这样做。

在写这篇文章之前我尝试了一些事情:

  • 我尝试使用
    ssh-keygen -t rsa -b 4096
    在我的 VPS 服务器上生成密钥。
  • 后来我就这么做了
    cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys id_rsa.pub
  • 然后我使用
    cat /root/.ssh/id_rsa
    复制私钥的内容并将其导入到 BitVise 上。

我也尝试了相反的方法,我在 BitVise 上生成了密钥,然后执行了完全相同的过程,但相反。将公钥复制到我的 SSH 服务器上。

最后我尝试使用 PuTTY,认为这可能是 BitVise 问题,但不,仍然被拒绝......

每次更改配置文件时,我都会

reboot

附加信息:

  • 在做上面提到的事情之前,我跑了
    apt update
    &
    apt upgrade
  • 我可以使用密码登录,但不能使用密钥...
  • 我仔细检查了一下,我的 id_rsa.pub 位于@
    /root/.ssh/authorized_keys
    ,内容就在那里

这是我的

/etc/ssh/sshd_config

#       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

Port XXXXX
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

LoginGraceTime 2m
StrictModes yes
MaxAuthTries 6
MaxSessions 10

PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
AuthorizedKeysFile      .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
PermitRootLogin no
linux ubuntu ssh rsa ssh-keys
1个回答
0
投票

您的 VPS 配置为拒绝通过 SSH 进行 root 登录,该参数位于最后:

PermitRootLogin no
。我假设您能够以其他用户身份登录(您说过密码有效)。

如果您尝试向其他用户帐户授予 BitVise 访问权限,则需要将公钥添加到该用户的

~/.ssh/authorized_keys
,并以该用户身份通过 SSH 登录。

如果您尝试授予 BitVise root 访问权限 - 完全、不受限制地访问该系统上的绝对所有 - 那么您可以通过将

PermitRootLogin
更改为
yes
来实现(但我认为这是一个非常非常糟糕的想法) .

(此外,在配置文件更改后,您不需要

reboot
- 只需重新启动该服务即可。如果您使用的发行版运行
systemd
,则
systemctl restart sshd
sudo systemctl restart sshd
应该可以解决问题。)

© www.soinside.com 2019 - 2024. All rights reserved.