Connecting to Another System Using the ssh Command
By default, each time you use the OpenSSH utilities to connect to a remote system, you must provide a username and password. When you connect to an OpenSSH server for the first time, the OpenSSH client prompts you to confirm that you're connected to the correct system.
Use the ssh command to log in to a remote system or to run a command on a remote system:
ssh [options] [user@]host [command]
In the preceding example, host is the name of the remote OpenSSH server to which you want to connect.
For example, to log on to host04
by using the same username as that being
used on the local system, run the following command:
ssh host04
To connect as a different user, specify the username and @
symbol before
the remote host name, for example:
ssh joe@host04
To run a command on the remote system and return to the local shell, specify the command as an argument:
ssh joe@host04 ls $HOME/.ssh
The ssh command logs you in, runs the command, and then closes the connection.
Example 5-1 Example of Connecting to a System
The following examples show how you
would connect to a remote host, host04
. You would need to confirm the
command action before establishing the connection.
ssh host04
The
following example output shows you the expected output from the preceding
command:The authenticity of host 'host04 (192.0.2.104)'
can't be established.
ED25519 key fingerprint is SHA256:iunRrbwnhwqkUrahjaodhsngtzwtF+RFHEjiaUdYaP8I.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'host04,192.0.2.104' (ED25519) to the
list of known hosts.
When you type yes
to accept the
connection to the server, the client adds the server's public host key to the
$HOME/.ssh/known_hosts
file. When you next connect to the remote
server, the client compares the key added to $HOME/.ssh/known_hosts
to the
one that the server supplies. If the keys do not match, you see a warning such as the
following:
...
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:fingerprint.
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in /home/user/.ssh/known_hosts:1
Host key for ipa has changed and you have requested strict checking.
Host key verification failed
...
Unless the remote server’s host key has changed for a known reason, such as an upgrade of either the SSH software or the server, avoid connecting to that machine until you have contacted its administrator about the situation.
For more information, see the ssh(1)
manual page.