Restart SSH: Restarting Your Secure Session

linuxvsunixSSH is a utility found in Linux and UNIX based systems. SSH is an acronym for Secure Socket Shell. The SSH utility features a command interface as well as protocol that lets you control a server from a remote location, over a network connection. It evolved out of a three utilities that were present in earlier versions of UNIX systems: rlogin, rcp and rsh. The SSH feature now lets you use a more secure version of these utilities, namely slogin, scp and ssh. This tutorial teaches you how to restart the SSH utility. We assume that you’re familiar with UNIX based systems and that you know how to connect to a remote server. You can check out this beginners course if you’re new to Linux/Unix

The data you send through the SSH utility is scrambled. This is to prevent unauthorized users or hackers getting their hands on it. SSH uses the RSA standard public key cryptography to connect and to validate the connection, andyour password and the data you send over the network is protected through encryption. A hacker with a normal computer will find it impossible to decrypt the information you pass through SSH. If you want to quickly and effectively learn how to operate a UNIX system like a system administrator, consider taking this system administration course with us.

Connecting to a Remote Server

Before you restart your SSH utility, you need to login to a remote server. You need to have an account name and password already created on the remote server. If you don’t have an account and password, ask a system administrator for help.Just use the following command to connect to it:

ssh username@www.remoteserver.com

Save the server host key (if you haven’t already) and then type the password. If the login name and password you’ve entered are correct, the session will begin (and your system authenticated). Once you’ve logged in successfully, you can start, restart and stop your session.

Checking the Status of your Session

You might also want to make sure your session is working fine. The start, stop and restart commands won’t work if it’s not. You can use the following command for that:

sudo /etc/init.d/ssh status

Check if the connection has been established and is still running. An error message (warning) will be displayed if the connection has problems. In this case, you may want to try reconnecting to the server.

Stopping a Session

We’re assuming that you’ve logged in as a root user. You need to have system administrator privileges to stop, start and restart the SSH utility. To stop a session (on an Ubuntu Linux system), use the following command:

sudo /etc/init.d/ssh start

You can also use the alternative command:

sudo service ssh start

Stopping a Session

To stop a session (on an Ubuntu Linux system), use the following command:

sudo /etc/init.d/ssh stop

You can also use the alternative command:

sudo service ssh stop

Restarting the Session

To restart a session (on an Ubuntu Linux system), type:

sudo /etc/init.d/ssh restart

The alternative command is:

sudo service ssh restart

Restarting SSH Sessions (and Starting, Stopping) for Newer Versions of Ubuntu Linux

For newer versions of Ubuntu, the /etc/init/d/ssh script has been changed into an Upstart based job. You will need different commands to restart, start and stop your SSH session.

To stop a session, use this:

sudo stop ssh

To start a session, use:

sudo start ssh

To restart SSH, type:

sudo restart ssh

To check the current status of the session, type:

sudo status ssh

Restarting SSH Sessions for CentOS/ Fedora/ RHEL and Redhat

To restart a CentOS/ Fedora/ RHEL and Redhat based system, type the following command:

/etc/init.d/sshd restart

The alternative command is:

servicesshd restart

Restarting SSH Sessions for Debian/ Ubuntu

To restart a Debian/ Ubuntu based system, you can use the following command:

/etc/init.d/ssh restart

The alternative command is:

servicessh restart

Restarting SSH Sessions for FreeBSD

To restart a FreeBSD based system, use the following command:

/etc/rc.d/sshd restart

Note

Some servers drop the connection if it’s idle too long. In this case, instead of reconnecting, you should change the TCP Keep Alive settings in your SSH config file. This way, the connection will always remain active.

How to restart (as well as stop and start) a session with a remote server is something every Linux user should know. If you’d like to learn more about SSH, take a look at this course to master the Linux command line.