Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
34 views

Linux Setup SSH - Linux Tutorials - Learn Linux Configuration

Uploaded by

John Williams
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Linux Setup SSH - Linux Tutorials - Learn Linux Configuration

Uploaded by

John Williams
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.

org/linux-setup-ssh

Menu

Linux: Setup SSH


6 March 2023 by Korbin Brown

The SSH protocol allows Linux administrators to log in to any number of remote
systems from their own command line terminal. SSH is a client-server service
providing secure, encrypted connections over a network connection. This allows us
terminal access to other Linux systems or really any device that accepts SSH
connections, such as routers and �rewalls, and other operating systems.

A user can also set up an SSH server on their own computer if they want to allow
incoming connections. This can be useful if you want to access your computer when
away from your desk, or you have other users on your system that need to use the
computer. In this tutorial, we will go over the step by step instructions to setup SSH
as both a client and server on all major Linux distros.

DID YOU KNOW?


In addition to providing us with a secure and encrypted way to log in to
remote systems, the SSH protocol can also be used to for port forwarding,
which allows us to encrypt the tra�c between two systems for pretty much
any protocol.

In this tutorial you will learn:

• How to install SSH Client and Server on all major Linux distros

1 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

• How to use the ssh command to log in to a remote server


• How to start, stop, enable, and disable the SSH service
• How to allow incoming SSH connections through the system �rewall
• Recommendations for SSH server con�guration and security

Linux: Setup SSH

So�ware Requirements and Linux Command Line Conventions

Category Requirements, Conventions or So�ware Version Used

System Any Linux distro

So�ware OpenSSH

Privileged access to your Linux system as root or via the sudo


Other
command.

# – requires given linux commands to be executed with root


privileges either directly as a root user or by use of sudo command
Conventions
$ – requires given linux commands to be executed as a regular non-
privileged user

2 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

How to Install SSH on Linux

The �rst thing we need to do is install SSH. There are separate so�ware packages
available depending on if you want to install the client package, server package, or
both.

• The OpenSSH Client package will allow you to use SSH to log in or initiate
connections to remote systems.
• The OpenSSH Server package will allow you to setup the SSH service and
accept incoming connections. It is not necessary (or recommended) to install
this package if you only plan to use SSH as a client.

The SSH command is generally available by default on all Linux distributions, but if
your system does not have it, you can use the appropriate command below to install
the OpenSSH client package with your systemʼs package manager. The second
command in each example below will install the Server package (skip if you do not
need it).

To install OpenSSH Client and Server on Ubuntu, Debian, and Linux Mint:

$ sudo apt update


$ sudo apt install openssh-client
$ sudo apt install openssh-server

To install OpenSSH Client and Server on Fedora, CentOS, AlmaLinux, and Red Hat:

$ sudo dnf install openssh


$ sudo dnf install openssh-server

3 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

To install OpenSSH Client and Server on Arch Linux and Manjaro:

$ sudo pacman -S openssh # all in one package

Using SSH Command


Example 1 Now that SSH is installed, we can use the ssh command to connect to
a remote server and login. The basic syntax is as follows, where user is the
username and linuxconfig.org is the remote server. You can also use the IP
address instead of hostname.

$ ssh user@linuxconfig.org

Example 2 The default port for SSH to listen on is 22. If the remote system is
running the SSH service on some non default port, you can specify that port with the
-p option in your command. The following example shows how you would SSH into
a remote system thatʼs running the service on port 2210.

$ ssh -p 2210 user@linuxconfig.org

Example 3 Having SSH installed also gives us access to the scp command. The scp
command in Linux is used to copy �les and directories to or from a remote system.
It works very similarly to the cp command, except that it copies �les to or from other
systems that are either on your local network or somewhere over the internet. Letʼs
look at a simple example where we use the scp command to copy a local �le named
file.txt to a remote server with hostname linuxconfig.org .

4 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

$ scp file.txt user@linuxconfig:/path/to/dest

NOTE – PASSWORDLESS LOGIN


If you get tired of typing in your password every time, you can authenticate
using RSA keys instead.

How to Con�gure SSH Server


To allow users to login to your system via SSH, we will show you how to control the
service and allow the connections through your �rewall in the steps below.

Step 1 To begin accepting incoming SSH connections, we need to start the SSH
service with the systemctl command. To start or stop the SSH server:

$ sudo systemctl start sshd


AND
$ sudo systemctl stop sshd

Step 2 To enable (make SSH start automatically at system boot), or disable the SSH
server:

$ sudo systemctl enable ssh


OR
$ sudo systemctl disable ssh

Step 3 Check whether the SSH server is running by using the systemctl status
command.

5 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

$ sudo systemctl status ssh

The sshd status indicates that the service is currently running

Step 4 In order to accept incoming connections, you will also need to allow the
service through your system �rewall. The commands for doing that may di�er
depending on your Linux distro. Use the appropriate ones below.
On Ubuntu and systems using ufw (uncomplicated �rewall):

$ sudo ufw allow ssh

On RHEL based distros or any others using �rewalld:

$ sudo firewall-cmd --zone=public --permanent --add-service=ssh


$ sudo firewall-cmd --reload

Or if you are just using iptables and no �rewall frontend:

6 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

$ sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT

Thatʼs all there is to it. As long as there is no physical router or �rewall blocking
connections to the SSH server, it should be ready to accept incoming connections.

Further SSH Server Recommendations

With your SSH server ready to accept incoming connections, there are some
con�guration and security recommendations that you can apply. We have compiled
some of the most important ones below, and given you links to more in depth
tutorials for further reading:

• How to make the most of OpenSSH – Copying �les between machines with
scp , key based authentication, saved logins, mounting �le systems over SSH
• SSH remote login syntax and examples – Enabling root login, executing
commands over SSH, using tar over SSH, adding SSH aliases
• How to secure SSH best practices – Using SSH keys, changing default port,
allow speci�c users to log in

Closing Thoughts
In this tutorial, we saw how to setup SSH on a Linux system. This included using SSH
as a client package and ssh command, along with setting up SSH as a service that
listens for incoming connections. SSH is an essential protocol for most Linux
systems, as it allows you to open remote terminals to any number of systems, or to
manage your own system from over the internet. We can also do other handy things
like copy �les remotely, or create encrypted tunnels for other protocols.

7 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

Related Linux Tutorials:

• An Introduction to Linux Automation, Tools and Techniques


• Can Linux Get Viruses? Exploring the Vulnerability of Linux…
• Things to do a�er installing Ubuntu 22.04 Jammy Jelly�sh…
• Linux Download
• Things to install on Ubuntu 22.04
• FTP client list and installation on Ubuntu 22.04 Linux…
• Linux Apache log analyzer
• List of best Kali Linux tools for penetration testing and…
• Mint 20: Better Than Ubuntu and Microso� Windows?
• Advanced Logging and Auditing on Linux

System Administration
commands, networking, security, ssh
Setup FTP server on Linux
MX Linux vs Ubuntu

Comments and Discussions

Start Discussion 0 replies

NEWSLETTER

Subscribe to Linux Career Newsletter to receive latest news, jobs, career advice and featured

8 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

con�guration tutorials.

SUBSCRIBE

WRITE FOR US

LinuxCon�g is looking for a technical writer(s) geared towards GNU/Linux and FLOSS
technologies. Your articles will feature various GNU/Linux con�guration tutorials and FLOSS
technologies used in combination with GNU/Linux operating system.

When writing your articles you will be expected to be able to keep up with a technological
advancement regarding the above mentioned technical area of expertise. You will work
independently and be able to produce at minimum 2 technical articles a month.

APPLY NOW

TAGS

18.04 administration apache applications backup bash beginner browser

centos centos8 commands database debian desktop development docker error


fedora �lesystem �rewall gaming gnome Hardware installation java kali manjaro
multimedia networking nvidia programming python redhat rhel8 scripting
security server ssh storage terminal ubuntu ubuntu 20.04 virtualization webapp
webserver

ABOUT US

FEATURED TUTORIALS

9 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

VIM tutorial for beginners

How to install the NVIDIA drivers on Ubuntu 20.04 Focal Fossa Linux

Bash Scripting Tutorial for Beginners

How to check CentOS version

How to �nd my IP address on Ubuntu 20.04 Focal Fossa Linux

Ubuntu 20.04 Remote Desktop Access from Windows 10

Howto mount USB drive in Linux

How to install missing ifcon�g command on Debian Linux

AMD Radeon Ubuntu 20.04 Driver Installation

Ubuntu Static IP con�guration

How to use bash array in a shell script

Linux IP forwarding – How to Disable/Enable

How to install Tweak Tool on Ubuntu 20.04 LTS Focal Fossa Linux

How to enable/disable �rewall on Ubuntu 18.04 Bionic Beaver Linux

Netplan static IP on Ubuntu con�guration

How to change from default to alternative Python version on Debian Linux

Set Kali root password and enable root login

How to Install Adobe Acrobat Reader on Ubuntu 20.04 Focal Fossa Linux

How to install the NVIDIA drivers on Ubuntu 18.04 Bionic Beaver Linux

How to check NVIDIA driver version on your Linux system

Nvidia RTX 3080 Ethereum Hashrate and Mining Overclock settings on HiveOS Linux

LATEST TUTORIALS

Introduction to Vagrant

Check CPU and RAM usage of a Kubernetes pod

Kubernetes vs Docker, whatʼs the di�erence?

Install and Use MicroK8s on Ubuntu

How to Create and Manage a Pod in Kubernetes

10 of 11 4/7/23, 12:26 PM
Linux: Setup SSH - Linux Tutorials - Learn Linux Config... https://linuxconfig.org/linux-setup-ssh

How to Create, Manage, and Expose a Service in Kubernetes

Control CPU and RAM usage in Kubernetes

How to Setup Minikube for Kubernetes

Choosing a Kubernetes Networking Addon

What is Kubernetes used for?

How to create a cron job in Kubernetes

kubeadm vs minikube, pros and cons

How to Create a Kubernetes Cluster

How to use helm package manager for Kubernetes

How to deploy WordPress on a Kubernetes cluster

kubectl command examples (cheat sheet)

How to manage and troubleshoot Kubernetes logs

How to Install Kubernetes on All Linux Distros

How to Manage Kubernetes Clusters With kubectl

How to Deploy an Application in Kubernetes

© 2023 TOSID Group Pty Ltd - LinuxCon�g.org

11 of 11 4/7/23, 12:26 PM

You might also like