ssh(secure-shell)
ssh(secure-shell)
In Linux, the most common way to get a shell prompt on a remote system
is to use Secure Shell (SSH). Most Linux systems (including Red Hat
Enterprise Linux) and macOS provide the OpenSSH command-line program
ssh for this purpose.
In this example, a user with a shell prompt on the machine host uses ssh to
log in to the remote Linux system remotehost as the user remoteuser:
[user@host ~]$ ssh remoteuser@remotehost
remoteuser@remotehost's password: password
[remoteuser@remotehost ~]$
Some systems (such as new cloud instances) do not allow users to use a
password to log in with ssh for tighter security. An alternative way to
authenticate to a remote machine without entering a password is through
public key authentication.
➢ The public key is used to verify the private key and it resides in
"~/.ssh/id-rsa.pub"
Logging Out
When you are finished using the shell and want to quit, you can choose one
of several ways to end the session. You can enter the exit command to
terminate the current shell session. Alternatively, finish a session by
pressing Ctrl+D.
To do this, you generate a matched pair of cryptographic key files. One is a private key,
the other a matching public key. The private key file is used as the authentication
credential and, like a password, must be kept secret and secure. The public key is
copied to systems the user wants to connect to, and is used to verify the private key.
The public key does not need to be secret.
You put a copy of the public key in your account on the server. When you try to log in,
the SSH server can use the public key to issue a challenge that can only be correctly
answered by using the private key. As a result, your ssh client can automatically
authenticate your login to the server with your unique copy of the private key. This
allows you to securely access systems in a way that doesn't require you to enter a
password interactively every time.
To create a private key and matching public key for authentication, use the ssh-keygen
command. By default, your private and public keys are saved in your ~/.ssh/id_rsa and
~/.ssh/id_rsa.pub files, respectively.
Before key-based authentication can be used, the public key needs to be copied to the
destination system. The ssh-copy-id command copies the public key of the SSH keypair
to the destination system. If you omit the path to the public key file while running ssh-
copy-id, it uses the default /home/user/.ssh/id_rsa.pub file.
After the public key is successfully transferred to a remote system, you can
authenticate to the remote system using the corresponding private key while logging
in to the remote system over SSH. If you omit the path to the private key file while
running the ssh command, it uses the default /home/user/.ssh/id_rsa file.
Lab Exercise
4. Use the ssh-copy-id command to send the public key of the SSH
key pair to student on servera.
1. From servera, copy files from serverb to serverc as the student user.
[root@servera ~]# scp student@serverb:~/Documents/*.txt student@serverc:~/
eg:
[root@serverb ~]# scp serverb:~/Pictures/* student@serverc:~/Pictures/
[root@serverb ~]# scp serverc:~/Desktop/* . ( “.” --> present location)