我正在尋找調整 ubuntu 雲端版本預設設置,其中拒絕 root 登入。
嘗試連接到此類機器會產生:
maxim@maxim-desktop:~/workspace/integration/deployengine$ ssh [email protected]
The authenticity of host 'ec2-204-236-252-95.compute-1.amazonaws.com (204.236.252.95)' can't be established.
RSA key fingerprint is 3f:96:f4:b3:b9:4b:4f:21:5f:00:38:2a:bb:41:19:1a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-204-236-252-95.compute-1.amazonaws.com' (RSA) to the list of known hosts.
Please login as the ubuntu user rather than root user.
Connection to ec2-204-236-252-95.compute-1.amazonaws.com closed.
我想知道在哪個設定檔中配置了透過 ssh 進行根阻止以及如何更改列印的訊息?
答案1
舊問題,但沒有人真正回答你,我也有同樣的問題:這個配置來自哪裡?
它起源於雲端初始化,正好在cc_ssh.py
裡面/usr/lib/python2.7/dist-packages/cloudinit/config
這又直接依賴文件/etc/cloud/cloud.cfg
。你找到一條線disable_root: true
。
您應該能夠透過調整使用者資料並添加 line 來覆蓋它disable_root: false
。您的雲端提供者應該使用戶資料可配置。
答案2
假設您的 sshd 配置有PermitRootLogin yes
.
sudo grep "login as the ubuntu user" /root/.??*
然而,我強烈建議您仔細閱讀並留意邁克·斯科特提供的連結。
根SSH
最後,如果您希望規避 Ubuntu 安全標準並恢復到允許 ssh 和 rsync 作為 root 的舊做法,此命令將為官方 Ubuntu 映像的新實例開啟它:
ssh -i KEYPAIR.pem ubuntu@HOSTNAME 'sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/'
不建議這樣做,但它可能是讓現有 EC2 自動化程式碼繼續運作的一種方法,直到您可以升級到上述 sudo 實踐。
我禁用 root SSH 登錄,因為任何啟用了 SSH 的面向公眾的伺服器都會日夜不斷地受到來自犯罪殭屍網路的 root 登入嘗試的攻擊。
文件在其他地方警告
很少需要啟用 Root 帳戶。作為 Ubuntu 系統管理員,您需要做的幾乎所有事情都可以透過 sudo 或 gksudo 完成。如果您確實需要持久的 Root 登錄,最好的選擇是使用以下命令模擬 Root 登入 shell...
sudo -i
答案3
答案在這裡:http://alestic.com/2009/04/ubuntu-ec2-sudo-ssh-rsync
將authorized_keys 檔案從ubuntu 帳號複製到root 帳號。密碼登入已停用,因此您必須擁有有效的 ssh 金鑰才能登入任何帳戶。
答案4
檢查/etc/ssh/sshd_config,選項名稱為“允許root登入”
PermitRootLogin
Specifies whether root can log in using ssh(1). The argument
must be “yes”, “without-password”, “forced-commands-only”, or
“no”.
更有用的設定之一是“不帶密碼”,它允許您以 root 身份登錄,但前提是您使用公鑰身份驗證。 man sshd_config 了解更多:)