متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 2System · Linux

How to install and enable the SSH server

You need SSH to manage a server remotely: log in, copy files, run Ansible. Many server images already have it; desktop and minimal images often do not. This how-to installs the OpenSSH server on RHEL and Ubuntu, starts it at boot, opens the firewall and tests the login — in about two minutes. For hardening (keys only, no root login) follow the full guide afterwards.

  • 5 الدروس
  • 10 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

2.1

The quick answer

RHEL, Rocky, Alma, Fedora:

dnf -y install openssh-server
systemctl enable --now sshd
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload

Ubuntu, Debian:

apt-get update && apt-get install -y openssh-server
systemctl enable --now ssh
ufw allow OpenSSH

2.2

Step by step

  1. Check if it is already there and running:
systemctl status sshd --no-pager
systemctl status ssh --no-pager
ss -ltnp | grep ':22 '

(The service is sshd on RHEL and ssh on Ubuntu.)

  1. Install the package openssh-server (commands above). The client ssh is a different package (openssh-clients / openssh-client) and is almost always installed.
  2. Start it now and at every boot with systemctl enable --now. On Ubuntu 22.10 and newer, ssh.socket listens on port 22 and starts ssh.service at the first connection — that is normal.
  3. Open the firewall for port 22 — on the server and in the cloud security group or network firewall if there is one.
  4. Find the address to connect to:
ip -br address
hostname -I
  1. Log in from another machine:
ssh admin@192.0.2.10
The authenticity of host '192.0.2.10 (192.0.2.10)' can't be established.
ED25519 key fingerprint is SHA256:Qx1v…
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Compare the fingerprint with the one on the server (ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub) before you type yes.

2.3

Check that it worked

systemctl is-active sshd
active
systemctl is-enabled sshd
enabled
ss -ltnp 'sport = :22'
LISTEN 0  128  0.0.0.0:22  0.0.0.0:*  users:(("sshd",pid=812,fd=3))
ssh -o ConnectTimeout=5 admin@192.0.2.10 'hostname; uptime'

(On Ubuntu use ssh instead of sshd in the systemctl lines.)

2.4

Common problems

ProblemCauseFix
Connection refusedThe service is not running, or listens on another port.systemctl status sshd; ss -ltnp for the port.
Connection timed outFirewall or cloud security group blocks port 22.Open the ssh service; check the security group / NACL.
Permission denied (publickey)Password login is off and your key is not on the server.See "How to log in with SSH keys"; use the cloud console to add the key.
Service fails: sshd: no hostkeys availableHost keys were deleted (for example in a template).ssh-keygen -A, then start the service again.
Unit sshd.service not found on UbuntuThe name is ssh there.systemctl status ssh.
REMOTE HOST IDENTIFICATION HAS CHANGEDThe server was rebuilt (new host keys) — or an attack.Check with the server owner, then ssh-keygen -R 192.0.2.10.

2.5

Go further

1What is the name of the SSH service on RHEL and on Ubuntu?

sshd on RHEL, ssh on Ubuntu.

2SSH gives "Connection timed out", the service is running. What do you check?

The firewall on the server and the cloud security group for port 22.

كل الأوامر في هذا الفصل