Tim Sullivan a122e0f328 Expanded explanation, added links (#21157)
* Expanded explanation, added links

The earlier version of this did not expand fully on usage patterns or how SSH operates. I added an explanation of why you don't need to specify the username, additional examples, and links for further investigation.

* Update index.md
2018-12-21 21:17:40 -05:00

46 lines
2.5 KiB
Markdown

---
title: Bash ssh (Secure SHell)
---
## Bash command: ssh
SSH (**S**ecure **SH**ell) is a secure method of remotely connecting to a Linux machine.
The basic syntax of the command is `ssh username@hostname`.
**Used to connect to a remote computer** It's full form is 'Secure Shell'. It's purpose is to connect to another remote computer using tcp. The address of the remote computer can be provided using an IP address or, if provided, an identifier.
If the remote computer requires user login, the form `ssh username@remote_address` can be used, which will then prompt for the user password on successful connection.
Example command:
`ssh pi@192.168.0.101`
This will connect to the computer in the local ip address of 192.168.0.101 and log in with the username pi.
Another way to use this command is to pipe a command directly to it.
For example:
To execute the command
`ls /tmp/doc`
on the computer with ip address 192.168.0.101, type the following command at a shell prompt:
`ssh 192.168.0.101 ls /tmp/doc`
After authenticating to the remote server, the contents of the remote directory will be displayed, and you will return to your local shell prompt.
* Hostname can be either an IP address or a FQDN.
* 'username@' can be excluded if the user currently logged into the shell has the same username as the desired user on the remote system.
* if the server is configured to listen to any port other than `22`, then you have to use `-p` option to specify the port. For example: `ssh -p 2024 123.456.789.012`.
SSH can rely on password-based authentication or key-based authentication. Password-based authentication is becoming less common as cloud solutions such as Amazon Web Services, Microsoft Azure, and Google Cloud Platform promote the usage of keys. If a system is configured for password-based authentication, once the connection is opened the system will prompt the user for the password. If the system is configured to use keys, the key can be added to the ssh-agent (more below) or specified with the -i switch like so: `ssh -i my_private_key.pem username@hostname`.
There are several advanced usage patterns such as key forwarding with the ssh-agent, which are described in the links below.
### More Information:
* [Wikipedia](https://en.wikipedia.org/wiki/Secure_Shell)
* [Digital Ocean's Guide to SSH Keys](https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2)
* [AWS's Guide to SSH Agent Forwarding](https://aws.amazon.com/blogs/security/securely-connect-to-linux-instances-running-in-a-private-amazon-vpc/)