SSH is a secure network protocol that allows remote access and file transfers between computers in a secure manner. It uses cryptographic keys and algorithms to authenticate users and encrypt data. Some common uses of SSH include remote login and command-line execution. An SSH client initiates an encrypted connection to an SSH server on a remote computer using the secure shell protocol after verifying authentication via keys or passwords. The document then provides examples of SSH commands and configurations for tasks like connecting to remote machines, transferring files, and running commands securely over SSH connections.
Report
Share
Report
Share
1 of 11
Download to read offline
More Related Content
SSH.pdf
1. SSH or Secure Shell program is renowned for its secure operation of network services via a
cryptographic network protocol. In most cases, the network interface in use has questionable
security hence the need for SSH.
Popular application implementations associated with SSH include:
remote login
command-line execution
The basis of SSH applications can be described in the following manner. Firstly, an active and
configured client-server architecture needs to pre-exist. Afterward, an SSH client instance is
used to make a connection attempt to the targeted SSH server.
An SSH client makes use of the secure shell protocol to initiate a connection with a remote
computer. The targeted remote computer needs to have an SSH server installed for it to
validate and authenticate the remote connection attempt from the client computer.
This article will walk us through some elite SSH cheats which can be useful in your day-to-day
client-to-server/remote machine connection and communication.
Quick manual access to the use of SSH can be accessed by running the following command
on your Linux terminal:
$ ssh
To edit your SSH configurations like access port and connection timeout, you will need to
access the configuration file /etc/ssh/ssh_config or /etc/ssh/sshd_config.
$ sudo nano /etc/ssh/ssh_config
2. OR
$ sudo vim /etc/ssh/sshd_config
To access a remote/server machine from a client machine via SSH, you will need to adhere to
the following command implementation:
$ ssh username@remote_ip_address
3. You will then be prompted for a password associated with the remote machine’s user before
gaining access.
Useful SSH Cheat Sheet for Linux
Other than gaining direct access to a remote machine and editing the SSH configuration file
to your preference, the following SSH cheats have been proven to be very useful in your
client-to-remote machine communication.
Generate SSH-Keygen
It is a recommendation to make use of the ed25519 algorithm while generating SSH keys.
Consider the implementation below using a random email address:
$ ssh-keygen -t ed25519 -C "linuxshelltips@gmail.com"
4. For compatibility reasons, you might decide to generate the key via RSA as demonstrated
below:
$ ssh-keygen -t rsa -b 4096 -C "user@linuxshelltips.com"
The -C flag associates each public key with a comment making it easy to link an email
address to its rightful public key. During SSH key generation, always remember to associate
each private key with a passphrase for security purposes.
5. Connect Server Using SSH Keys
To connect to a remote machine via a specific private key, refer to the following command
implementation:
For ed25519 algorithm generated private keys:
$ ssh -i $HOME/.ssh/id_ed25519 ubuntu@192.168.100.29
6. For RSA-generated private keys:
$ ssh -i $HOME/.ssh/id_rsa ubuntu@192.168.100.29
Connect Server Using Authorized Keys
If you aim to use your SSH keys (public keys) with a server system or service like Github, you
will need to append a copy of the keys with the file ~/.ssh/authorized_keys on the
remote/server system as demonstrated below.
7. $ cat ~/.ssh/id_rsa.pub | ssh ubuntu@192.168.100.29 "mkdir -p
~/.ssh && cat >> ~/.ssh/authorized_keys"
Alternatively, the following command also works:
$ ssh-copy-id ubuntu@192.168.100.29
From here, we can connect to the remote machine without being prompted for a password:
$ ssh ubuntu@192.168.100.29
8. SCP Commands for Upload/Download Files
When wanting to perform file uploads on remote machines:
$ scp simple.txt ubuntu@192.168.100.29:/home/ubuntu/Downloads
When wanting to perform recursive local folder/directory upload to a remote machine:
$ scp -rp mypackage ubuntu@192.168.100.29:/home/ubuntu/Downloads
9. Downloading/retrieving a file from a remote machine:
$ scp ubuntu@192.168.100.29:/home/ubuntu/Downloads/simple.txt
/home/dnyce/Downloads
Downloading/retrieving a folder/directory recursively from a remote machine:
$ scp -rp
ubuntu@192.168.100.29:/home/ubuntu/Downloads/mypackage
/home/dnyce/Downloads
10. Using Non-Standard SSH Ports
If the SSH server is running on a non-standard port like 3333, your connection should be
implemented in the following manner:
$ ssh -p 3333 ubuntu@192.168.100.29
Running Commands on Remote Machines
If we want to execute a command on the remote machine like a system update or ping
command after a successful SSH connection, we will implement the following command:
$ ssh -t ubuntu@192.168.100.29 'sudo apt update'
Because we are executing a sudo-privileged command, you will be asked for a user
password.