更新:設法修復它,但不確定為什麼會發生

更新:設法修復它,但不確定為什麼會發生

背景

我有一個透過 ras 金鑰設定了 SSH 存取的伺服器。不允許密碼存取。

一切正常。我的使用者(我稱之為 USER1)和 root 可以使用各自的金鑰登入。

可能引起問題的變更

昨天我按照說明對伺服器進行了一些更改在本文中,以便授予新使用者 (USER2) 對一個資料夾(Web 根目錄)的有限存取權。我還按照以下說明進行操作本文

為了總結這些更改,我建立了一個新使用者 (USER2),並執行了bindfsWeb 根 ( /home/user1/sites/domain/public/) 到/home/user2/domain/public/) 的操作。根據這些文章,還完成了一些其他操作,但據我所知,這些操作都不會影響 USER1 的權限和 SSH 存取。所以我不會嘗試在這裡重申它們。

根據其中一篇文章,我還在文件中添加了以下內容sshd_config

subsystem sftp internal-sftp
Match User USER2
ChrootDirectory %h
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp

據我所知,這是自我上次使用 USER1 登入以來唯一發生的變化。

問題

進行上述更改後,第二天(今天)我無法登入。我收到錯誤,Permission denied (publickey)..

我已遵循所有標準建議來為~/home/USER1/.ssh資料夾和~/home/USER1/.ssh/authorized_keys檔案設定正確的權限和所有權。雖然,我昨天的操作沒有改變它們,所以我基本上只是重新應用現有的權限。

我的文件內容/etc/ssh/sshd_config是:

Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes

AuthorizedKeysFile  %h/.ssh/authorized_keys
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
PasswordAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
UsePAM yes
Subsystem sftp /usr/lib/openssh/sftp-server

Match User USER2
PasswordAuthentication yes
ChrootDirectory %h
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp

AuthorizedKeysFile %h/.ssh/authorized_keys之前被註解掉了。我在嘗試解決此問題時取消了評論。

我不知道是什麼阻止我的 USER1 進行基於金鑰的 SSH 存取。如果有任何進一步的資訊有幫助,請告訴我。

更新:設法修復它,但不確定為什麼會發生

仔細檢查所有權限是否正確,並且檔案中沒有任何奇怪的內容後sshd-config,我將 ssh 設定為允許密碼登錄,然後將 id_rsa.pub 檔案(使用ssh-copy-id)重新複製到伺服器。

這已經恢復了我使用金鑰對 USER1 的存取權。

我不完全明白為什麼會出現這個問題,我計劃在其他伺服器上使用這些文章中的說明(因為事實證明,這是一種非常有用的方法,可以授予開發人員(例如)嚴格的SFTP 存取權(僅限)網站,並有權進行文件更改,因此,如果有人有時間指出說明中的錯誤,請這樣做。

為了讓您免於閱讀這些文章,以下是我所採取的步驟的詳細說明:

mkdir -p /home/user2/websites/application1
chown -Rf user2:user2 /home/user2/websites
chmod -Rf 770 /home/user2/websites

添加以下內容到/etc/fstab

bindfs#/home/user1/websites/domain/public /home/user2/websites/application1 fuse force-user=user2,force-group=user2,create-for-user=user1,create-for-group=user1,create-with-perms=0770,chgrp-ignore,chown-ignore,chmod-ignore 0 0

chown user1:user1 /home/user1/websites/domain/public
chmod 770 /home/user1/websites/domain/public

創建了新用戶:

sudo useradd -d /home/user2/website/application1 user2
sudo passwd user2

新增到 sshd-config

subsystem sftp internal-sftp
Match User user2
ChrootDirectory %h
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp

然後,sudo service ssh restart

問題

所以我修改後的問題是,在上述步驟中user1使用其金鑰進行 ssh 存取會導致什麼?

相關內容