Ssh

“SSH 虛擬資訊亭”。“PermitEmptyPasswords 是”有效嗎?- 如何使ssh 使用者密碼為空,以便隨機使用者使用?

  • May 1, 2016

如何ssh使用空密碼創建正確的安全帳戶以執行受信任的二進製文件?我想為隨機使用者製作一種“虛擬 ssh Kiosk”,同時將“展示應用程序”限制在 ssh“偽使用者”後面。

我所說的“安全”是指“為隨機訪問者執行展示應用程序的伺服器安全”。基本上將 ssh 帳戶後面的應用程序作為服務提供服務,類似於 https 服務網站的方式。

(為了這個問題,我們假設我們信任/bin/cat/usr/bin/cat- 取決於伺服器的系統,請檢查您的系統which echo

在處理https://goo.gl/TjhrWd時,我遇到了將密碼設為空的問題。PAM 拒絕它。

它是如何配置的

這是我在為使用者設置密碼時使用和工作的配置cat- 它也在https://goo.gl/TjhrWd中進行了描述:

# below configured on Ubuntu Server 14.04 LTS
addgroup catonly
CHROOT=/var/chroot/cat
# now let's make pseudo-shell binary, executing your ForceCommand (check source)
# you can use bash as default shell instead, I prefer sth less bloated.
cd /tmp
wget 'https://gist.githubusercontent.com/gwpl/abcbc74c2bf377945a49097237edfb9b/raw/1993e8acc4bd66329959b1a658fcce4296d2a80c/only_exec_command.c'
gcc only_exec_command.c -static -o only_exec_command
mkdir -p "$CHROOT"/{bin,lib,lib64,dev/pts,home/cat}
chown root:root /var/chroot "$CHROOT"
# dependig on distro it might be /usr/bin/cat -> check with `which cat`
useradd -d /home/cat -s /bin/only_exec_command -M -N -g catonly cat
passwd -d cat
# Let's make chroot
cp /tmp/only_exec_command "$CHROOT"/bin/
cp /bin/cat "$CHROOT"/bin/
mknod -m 666 "$CHROOT"/dev/null c 1 3
ldd /bin/cat # tells us which libraries to copy
cp /lib/x86_64-linux-gnu/libc.so.6 "$CHROOT"/lib
cp /lib64/ld-linux-x86-64.so.2 "$CHROOT"/lib64
chown cat:catonly "$CHROOT"/home/cat
chown root:root /var/chroot/cat /var/chroot /var
$ $EDITOR /etc/ssh/sshd_config # add:
Match user cat
      ChrootDirectory /var/chroot/cat
      X11Forwarding no
      AllowTcpForwarding no
      # dependig on distro it might be /usr/bin/cat -> check with `which cat`
      ForceCommand /bin/cat
      PasswordAuthentication yes
      PermitEmptyPasswords yes

症狀表明它是 PAM

但是嘗試ssh,會導致要求輸入密碼,並在拒絕時提供空結果:

ssh echo@1.2.3.4
echo@1.2.3.4's password:
Permission denied, please try again.

在調試模式下執行的伺服器端,日誌中沒有任何有趣的內容,讓我引用伺服器端部分,在登錄期間,輸入空密碼後:

/usr/sbin/sshd -ddd -p 1234
(...)
debug1: userauth-request for user echo service ssh-connection method password [preauth]
debug1: attempt 2 failures 1 [preauth]
debug2: input_userauth_request: try method password [preauth]
debug3: mm_auth_password entering [preauth]
debug3: mm_request_send entering: type 12 [preauth]
debug3: mm_auth_password: waiting for MONITOR_ANS_AUTHPASSWORD [preauth]
debug3: mm_request_receive_expect entering: type 13 [preauth]
debug3: mm_request_receive entering [preauth]
debug3: mm_request_receive entering
debug3: monitor_read: checking request 12
debug3: PAM: sshpam_passwd_conv called with 1 messages
debug1: PAM: password authentication failed for echo: Authentication failure
debug3: mm_answer_authpassword: sending result 0
debug3: mm_request_send entering: type 13
Failed password for echo from 192.168.1.1 port 43816 ssh2
debug3: mm_auth_password: user not authenticated [preauth]
debug3: userauth_finish: failure partial=0 next methods="publickey,password" [preauth]

您還需要告訴PAM您要允許空密碼。有一些過時的教程描述了這一點。但簡而言之:

sudo sed -i 's/nullok_secure/nullok/' /etc/pam.d/common-auth

應該做的工作。

要正確保護ssh 訪問,您不能允許免身份驗證登錄。設置一個 RSA 密鑰進行身份驗證,然後客戶端可以使用它而不需要密碼。

引用自:https://unix.stackexchange.com/questions/280168