Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ PasswordAuthentication no

4. **ذخیره و خروج از ویرایشگر**: اگر از `nano` استفاده می‌کنید، می‌توانید با فشار دادن `Ctrl + O` ذخیره کنید و با فشار دادن `Ctrl + X` خارج شوید.

5. **مهم — بررسی بازنویسی (override) مربوط به Cloud-Init**: در بسیاری از سرورهای ابری (برای مثال image‌های اوبونتو در Azure، AWS، Oracle Cloud، Hetzner، Vultr و ...)، یک فایل تنظیمات جداگانه، ورود با رمز عبور را دوباره فعال می‌کند. فایل اصلی `sshd_config` این فایل‌ها را در ابتدای خود با خطی مانند `Include /etc/ssh/sshd_config.d/*.conf` بارگذاری می‌کند و SSH برای هر گزینه از **اولین** مقداری که پیدا کند استفاده می‌کند؛ بنابراین مقدار داخل این فایل، مقداری را که در مرحله قبل تنظیم کردید بازنویسی می‌کند. این رایج‌ترین دلیلی است که چرا با وجود تنظیم `PasswordAuthentication no` در فایل اصلی، ورود با رمز عبور همچنان کار می‌کند.

بررسی کنید که آیا این فایل وجود دارد و در صورت وجود، آن را باز کنید:

<div dir=ltr markdown=1>

```bash
sudo nano /etc/ssh/sshd_config.d/50-cloud-init.conf
```
</div>

اگر این فایل وجود دارد و شامل `PasswordAuthentication yes` است، آن را به

<div dir=ltr markdown=1>

```bash
PasswordAuthentication no
```
</div>
تغییر دهید، سپس مانند مرحله قبل ذخیره کرده و خارج شوید. (اگر این فایل وجود ندارد، می‌توانید از این مرحله عبور کنید.)

### گام ۳: راه‌اندازی مجدد سرویس SSH

پس از ایجاد تغییرات در فایل `sshd_config`، باید سرویس SSH را برای اعمال تغییرات مجدداً راه‌اندازی کنید.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ Before you disable password authentication, make sure you have key-based authent

4. **Save and Exit the Editor**: If you are using `nano`, you can save by pressing `Ctrl + O` and exit by pressing `Ctrl + X`.

5. **Important — Check for a Cloud-Init Override**: On many cloud servers (for example, Ubuntu images on Azure, AWS, Oracle Cloud, Hetzner, Vultr, etc.), an additional drop-in configuration file re-enables password login. The main `sshd_config` loads these files near its top with a line such as `Include /etc/ssh/sshd_config.d/*.conf`, and SSH uses the **first** value it finds for each option — so a value inside the drop-in file overrides the one you set above. This is the most common reason password login still works even after setting `PasswordAuthentication no` in the main file.

Check whether this file exists and, if so, open it:
```bash
sudo nano /etc/ssh/sshd_config.d/50-cloud-init.conf
```
If the file exists and contains `PasswordAuthentication yes`, change it to:
```bash
PasswordAuthentication no
```
Then save and exit as in the previous step. (If the file does not exist, you can skip this step.)

### Step 3: Restart the SSH Service

After making changes to the `sshd_config` file, you need to restart the SSH service for the changes to take effect.
Expand Down