2018-11-15 12:06:21 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
category-page: intermediate
|
2018-11-16 12:47:48 +00:00
|
|
|
category-title: Intermediate commands
|
2018-11-15 20:09:21 +00:00
|
|
|
tags: remote connection host server file
|
2018-11-15 12:06:21 +00:00
|
|
|
author: Announ Marwan
|
|
|
|
title: ssh
|
|
|
|
---
|
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
The <code>ssh</code> command is used to operate with a remote machine using
|
|
|
|
the <i>ssh</i> protocol. It's commonly used for logging into a remote
|
|
|
|
machine and execute commands from a terminal interface.
|
2018-11-15 12:06:21 +00:00
|
|
|
|
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
<h3>Log into a server</h3>
|
2018-11-15 12:06:21 +00:00
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
To log in a remote server you need an user account which is
|
|
|
|
usually created by the server admin and a password.
|
2018-11-15 12:06:21 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
localhost:[~]> ssh username@remote-server
|
|
|
|
remote-server:[~]>
|
|
|
|
</pre>
|
2018-11-15 12:06:21 +00:00
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
Once you're logged in, the local machine shell will be
|
|
|
|
<i>replaced</i> by the remote server's one
|
2018-11-15 12:06:21 +00:00
|
|
|
|
|
|
|
<br>
|
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
<h3>Log out of a server</h3>
|
2018-11-15 12:06:21 +00:00
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
<ul>
|
|
|
|
<li>Press <code>⌘ + D</code></li>
|
|
|
|
<li>Run the command <code>logout</code></li>
|
|
|
|
<li>Run the command <code>exit</code></li>
|
|
|
|
</ul>
|
2018-11-15 12:06:21 +00:00
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
<h3>Run a command on a remote machine</h3>
|
2018-11-15 12:06:21 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
localhost:[~]:> ssh user@remote-host "ls test"
|
|
|
|
online-backup.dat
|
|
|
|
online-storage
|
|
|
|
unix-dedicated-server.txt
|
|
|
|
</pre>
|
2018-11-15 12:06:21 +00:00
|
|
|
|
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
<h3>Debug the client</h3>
|
2018-11-15 12:06:21 +00:00
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
Debugging the ssh client can be useful to resolve connection errors.
|
2018-11-15 12:06:21 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
localhost:[~]:> ssh -v user@remote-host
|
|
|
|
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
|
|
|
|
debug1: Reading configuration data /etc/ssh/ssh_config
|
|
|
|
debug1: Applying options for *
|
|
|
|
debug1: Connecting to remote-host [172.22.200.140] port 22.
|
|
|
|
debug1: Connection established.
|
|
|
|
debug1: identity file /home/user/.ssh/identity type -1
|
|
|
|
debug1: identity file /home/user/.ssh/id_rsa type -1
|
|
|
|
debug1: identity file /home/user/.ssh/id_dsa type 2
|
|
|
|
debug1: loaded 3 keys
|
|
|
|
...
|
2018-11-15 12:06:21 +00:00
|
|
|
</pre>
|