0Pricing
Linux Command Line Mastery · Урок

Управление ключами безопасной оболочки

Реализуйте беспарольную аутентификацию SSH с помощью пар ключей для повышения безопасности и удобства.

«Управление ключами безопасной оболочки» — бесплатный урок Linux Command Line Mastery на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Linux Command Line Mastery, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Linux Command Line Mastery содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

What are SSH Keys?

SSH keys are a secure way to log into a remote server without needing a password. Think of them as a digital key and lock system.

  • They provide stronger security than traditional passwords.
  • They offer convenience by enabling passwordless logins.
  • This lesson will guide you through setting them up.

Public and Private Key Pair

An SSH key system uses two parts: a public key and a private key.

  • Your private key stays on your local computer and must be kept secret. Never share it!
  • Your public key can be freely shared. You place it on any server you want to connect to.
  • When you try to connect, the server uses your public key to verify your private key, allowing access.

Generating Your Own SSH Keys

You create an SSH key pair using the ssh-keygen command in your terminal.

By default, it creates keys in the ~/.ssh/ directory (a hidden folder in your home directory). The most common key type is RSA.

You'll be prompted for a passphrase. This adds an extra layer of security to your private key, encrypting it. It's highly recommended!

Hands-on: Using `ssh-keygen`

Let's generate an RSA key pair. When prompted, you can press Enter to use default file locations and choose a strong passphrase (or leave it empty for no passphrase, though not recommended for security).

ssh-keygen -t rsa -b 4096

Understanding Key Files

After running ssh-keygen, you'll find two new files in your ~/.ssh/ directory:

  • id_rsa: This is your private key. Keep it safe and never share it!
  • id_rsa.pub: This is your public key. You'll copy this to remote servers.

The command also shows a key fingerprint, a unique identifier for your key pair.

Copying Your Public Key to a Server

To enable passwordless login, your public key needs to be on the remote server. The easiest way to do this is with the ssh-copy-id command.

It automatically appends your public key to the ~/.ssh/authorized_keys file on the server. You'll need to enter the server's password just this one time.

ssh-copy-id user@remote_host

Manual Public Key Installation

If ssh-copy-id isn't available on your system, you can manually copy your public key. This involves reading your local public key and piping it to the remote server via SSH, appending it to the authorized_keys file.

Make sure the .ssh directory exists and has correct permissions on the server (chmod 700 ~/.ssh).

cat ~/.ssh/id_rsa.pub | ssh user@remote_host "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"

Testing Passwordless Login

Once your public key is on the server, try logging in. If you set a passphrase, you'll be prompted for it. If not, you should connect directly without any password prompts!

This confirms that your SSH key authentication is working correctly.

ssh user@remote_host

Using `ssh-agent` for Convenience

If your private key has a passphrase, you'll be asked for it every time you connect. The SSH agent helps by storing your decrypted private key in memory.

  • Start the agent: eval "$(ssh-agent -s)"
  • Add your key: ssh-add ~/.ssh/id_rsa (enter passphrase once)

Now you can connect multiple times without re-entering your passphrase until the agent restarts.

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

Quick Check: SSH Key Files

Which of the following files contains your public key and is safe to share with remote servers?

Recap: Secure Key Management

You've learned how to set up and manage SSH key pairs for secure, passwordless authentication.

  • Generate keys with ssh-keygen.
  • Understand private (id_rsa) and public (id_rsa.pub) keys.
  • Copy public keys to servers using ssh-copy-id or manually.
  • Use ssh-agent and ssh-add for passphrase convenience.

SSH keys are a fundamental tool for efficient and secure remote access in Linux!

Часто задаваемые вопросы

Урок «Управление ключами безопасной оболочки» бесплатный?

Да — полный текст урока «Управление ключами безопасной оболочки» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Linux Command Line Mastery, подпишись на CoddyKit PRO. Курс Linux Command Line Mastery содержит 4 уроков всего.

Чему я научусь в уроке «Управление ключами безопасной оболочки»?

Реализуйте беспарольную аутентификацию SSH с помощью пар ключей для повышения безопасности и удобства. Ты практикуешь Linux Command Line Mastery с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Linux Command Line Mastery?

Предыдущий опыт не требуется. Linux Command Line Mastery на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.

Сколько времени занимает урок «Управление ключами безопасной оболочки»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Linux Command Line Mastery?

Да. Каждый урок Linux Command Line Mastery включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Диагностика сети: `traceroute`, `nslookup`, `dig`
  2. Управление брандмауэром: `ufw`, `firewalld`, `iptables`
  3. Управление ключами безопасной оболочки
  4. Захват и анализ трафика с tcpdump
← Назад к Linux Command Line Mastery