> For the complete documentation index, see [llms.txt](https://notes.mikaelsamvelian.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.mikaelsamvelian.com/linux-fundamentals/server-administration/ssh.md).

# SSH

The ssh command is used for logging into the remote systems, transfer files between systems and for executing commands on a remote machine. SSH stands for secure shell and is used to provide an encrypted secured connection between two hosts over an insecure network like the internet.

Reference: <https://www.ssh.com/ssh/command/>

#### Passwordless Authentication Using SSH <a href="#passwordless-authentication-using-ssh" id="passwordless-authentication-using-ssh"></a>

Using this method, we can ssh into hosts without entering the password. This method is also useful when we want some scripts to perform ssh-related tasks.

Steps for setting up a passwordless authentication with a remote host:

1. Install openssh package which contains all the commands related to ssh.
2. Generate a key pair using the ssh-keygen command.
3. After running the ssh-keygen command successfully, we should see two keys present in the `~/.ssh` directory. `id_rsa` is the private key and `id_rsa.pub` is the public key. Do note that the private key can only be read and modified by you.
4. Transfer the public key to the remote host
   1. There are multiple ways to transfer the public key to the remote server. We will look at one of the most common ways of doing it using the ssh-copy-id command.
   2. Install the openssh-clients package to use ssh-copy-id command.
5. Our public key should be in `~/.ssh/authorized_keys` now.

`~/.ssh/authorized_key` contains a list of public keys. The users associated with these public keys have the ssh access into the remote host.

#### How to run commands on a remote host ? <a href="#how-to-run-commands-on-a-remote-host" id="how-to-run-commands-on-a-remote-host"></a>

General syntax: ssh \\\<user>@\\\<hostname/hostip> \\\<command>

#### How to transfer files from one host to another host ? <a href="#how-to-transfer-files-from-one-host-to-another-host" id="how-to-transfer-files-from-one-host-to-another-host"></a>

General syntax: scp \\\<source> \\\<destination>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://notes.mikaelsamvelian.com/linux-fundamentals/server-administration/ssh.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
