2017-08-14 84 views
0

我遇到意外的行爲,使用acbuild run。爲了習慣這個想法,首先需要一個運行SSH主機的基於CentOS7的容器。以下引用的裸露CentOS 7容器爲centos7.aci是使用here給出的指令在最新的CentOS7安裝上創建的。 用於構建SSHD ACI的腳本rkt/image building:acbuild運行指令「忽略」

#! /bin/bash 
acbuild begin ./centos7.aci 
acbuild run -- yum install -y openssh-server 
acbuild run -- mkdir /var/run/sshd 
acbuild run -- sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config 
acbuild run -- sed '[email protected]\s*required\s*[email protected] optional [email protected]' -i /etc/pam.d/sshd 
acbuild run -- ssh-keygen -A -C "" -N "" -q 
acbuild run -- echo 'root:screencast' | chpasswd 
acbuild set-name centos7-sshd 
acbuild set-exec -- /usr/sbin/sshd -D 
acbuild port add ssh tcp 22 
acbuild write --overwrite centos7-sshd.aci 
acbuild end 

當它紡起來使用rkt run --insecure-options=image ./centos7-sshd.aci 服務器運行,但連接嘗試失敗,因爲密碼不被接受。如果我使用rkt enter進入正在運行的容器並重新運行echo 'root:screencast' | chpasswd裏面,我可以登錄。因此,acbuild運行指令剛剛沒有工作出於某種原因...爲了測試更多,我用 acbuild run -- mkdir ~/.ssh acbuild run -- echo "<rkt host SSH public key>「 >> ~/.ssh/authorized_keys

替換它來啓用基於密碼而不是密碼登錄。它不起作用:關鍵是被拒絕。原因很明顯,一旦你看看容器:~/.ssh/中沒有authorized_keys文件。如果在密鑰追加嘗試之前添加
acbuild run -- touch ~/.ssh/authorized_keys指令,則該文件已創建,但仍爲空。所以再次一個acbuild運行指令不起作用 - 沒有錯誤通知。可能與「忽略」指令使用>>|等操作符有關嗎?我見過的示例中顯示的所有命令都不使用任何此類運算符,但docs沒有提及任何內容,Google搜索也沒有幫助。在碼頭文件RUN指示他們也很好......這裏出了什麼問題?

PS:我試圖用chroot而不是默認的systemd-nspawn引擎中的「忽略」 acbuild run說明=>相同的結果

PPS:沒有acbuild標籤又在計算器上,所以我不得不來標記這是rkt - 能夠有足夠聲譽的人創造一個嗎? Thx

回答

0

好吧,我明白了使用acbuild run --debug選項會發生什麼。 當

acbuild run -- echo 'root:screencast' | chpasswd

被執行返回Running: [echo root:screencast],該管的主機上執行。爲了獲得預期的結果應該是

acbuild run -- /bin/sh -c "echo 'root:screencast' | chpasswd"

或以普通形式

acbuild run -- /bin/sh -c "<cmd with pipes>"

的解釋here