Restart Openssh Server



Introduction

One of the biggest and most welcome changes to the Windows 10 1809 update and in Windows Server 2019 was the addition of the OpenSSH Client and OpenSSH Server features. It is now incredibly easy to SSH into a Windows Workstation/Server using native tools that are now builtin to the Operating System. In the past this was only possible by using complicated tools and odd workarounds in order to get an SSH-like implementation to work correctly. You can also use the SSH commands right from the Windows command line (CMD, PowerShell), without needing third-party tools or odd commands. This is a very nice change that Microsoft has added, since it is much easier to remotely manage a Windows through the Command Line instead of the GUI, and having the ability to use the same tools on both Windows and Linux is a big advantage.

You can log into the server using putty software. Putty software can be downloaded from the website putty.org and you can connect to your server via SSH. Use systemctl command instead of ‘service’ command to restart service on CentOS 7 and RHEL 7 servers. OpenSSH Server options, such as changing the login banner and locking down security options are done in the C. You will need to restart the OpenSSH Server service in order to apply the change. Once the change has been made, the log file (sshd.log) can be found in the C:ProgramDatasshlogs directory.

Note: I have only tested this on Windows 10 Pro for Workstations (Version 1809 Build 17763.253) and on Windows Server 2019 Standard.

Installation

Installing the OpenSSH Client and OpenSSH Server options can be done through either the Settings app or through the Command Line.

GUI Installation

To install through the GUI, go to Settings -> Apps -> Apps & Features -> Manage optional features -> Add a feature. You should see the two options in the list of available features that can be installed:

OpenSSH Client
OpenSSH Server

Highlight each option and click the Install button to install the feature. If the options are missing, then you are not on the latest version/patch level of Windows 10 or Windows Server 2019. A restart should not be necessary after adding these features, but the newly installed services will need to be started and configured to automatically start at boot.

Command Line Installation

To install through the Command Line, open an elevated PowerShell console in order to proceed. To confirm that you are able to install the OpenSSH Client and OpenSSH Server features, run the following command:

If those two options are present, run the following two commands to install the features:

Like installing through the Settings app, a restart should not be necessary after adding these features. The newly installed services will need to be started and configured to automatically start at boot.

Services Start

In order to start using OpenSSH Server, the associated services will need to be started first. This can be done through either the Services MMC console or through the Command Line.

Services MMC Console

Open the Services MMC Console (Win + R, and type in services.mmc) and find the two Services that are related to OpenSSH Server:

OpenSSH Authentication Agent
OpenSSH Server

Right-click on each service and select Properties. Under Service Status, click the Start button to start the service. To configure the service to start automatically at boot, change the Startup Type drop-down menu to Automatic and click Apply.

Command Line Services

To start the OpenSSH Server services and enable them to run automatically, there are a few command that you will need to run. To do this, open an elevated PowerShell console and run the following commands to start the OpenSSH Server:

To have these services start automatically at boot, there are two additional commands to run as well:

After this has been completed, you should be able to connect to your Windows installation over SSH.

Using OpenSSH Client

The OpenSSH Client can be used exactly the same way as you would on any Linux/Unix host. It will work through the regular Command Line and in PowerShell:

Here is the same output from a Linux environment:

I won’t go into the details on how to use any of these advanced options, there are very good tutorials on how to use the OpenSSH Client on other sites. The behaviour of OpenSSH Client on Windows should be almost exactly the same as on a Linux environment. So far I haven’t run into any issues with connectivity.

Connecting to OpenSSH Server

There is nothing special required to connect to a Windows host, it behaves exactly the same way as any other SSH host. There are a few different username formats that you can use:

One of the benefits is the ability to login with a Microsoft account if you are using that as your username. It is a bit unusual to see an email address used this way, but I am glad that Microsoft made sure that this functionality worked correctly:

There is nothing more to OpenSSH Server, you can manage your Windows host from the command line once you are logged in. If you want to do any further customization or need some basic troubleshooting, there is additional information below.

Change the Default Shell

By default when you login to a Windows installation with SSH, it defaults to the regular Command Prompt (cmd.exe). I prefer PowerShell for everyday usage, and it is easy to switch to PowerShell once you login, but you can change the default shell to save yourself some time if you are going to be using this feature often.

This is done through the Registry Editor, which will run with Administrator privileges. You need to navigate to the following key:

Create a new string called DefaultShell and give it the following value:

Restart the OpenSSH Server Service and the next time that you login with SSH, you should automatically go to PowerShell. I have tried making this work with Bash, but it doesn’t seem to be supported yet.

If you do want to use Bash, just type in bash.exe to switch to it.

Additional Settings

There are a few customizations that you can do to the OpenSSH Server service if needed. Since this is a port of the OpenSSH Server, the customization is done in a very similar way. To begin, the directory where all of the associated executable files are found is in the C:WindowsSystem32OpenSSH directory:

The other important directory for OpenSSH Server is the C:ProgramDatassh folder, which contains the configuration files and log files.

OpenSSH Server options, such as changing the login banner and locking down security options are done in the C:ProgramDatasshsshd_config file.

Drivers archos laptops & desktops. Not all options can be used on a Windows host. For more information, you can refer to the official Wiki article on what options are supported:

Troubleshooting

If you need to view the log file for OpenSSH Server, you need to make a quick change to the configuration file (C:ProgramDatasshsshd_config) to enable logging:

Make the following change:

You will need to restart the OpenSSH Server service in order to apply the change. Once the change has been made, the log file (sshd.log) can be found in the C:ProgramDatasshlogs directory.

Sources

You must have server root login details to restart SSH service. The server login details will be provided by your webhosting company/Datacenter. You can log into the server using putty software. Putty software can be downloaded from the website putty.org and you can connect to your server via SSH. Use systemctl command instead of ‘service’ command to restart service on CentOS 7 and RHEL 7 servers. RHEL 7 and CentOS 7 migrated to Systemd and commands like ‘service’ and ‘chkconfig’ is now done using ‘systemctl’.

Example:

root@server [~]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service
In the above CentOS 7 server you can see that “service sshd restart” command gets redirected to new command “systemctl restart sshd.service”. SSH Service is restarted but it shows from now on you should use “systemctl” command to restart instead of using ‘service’ command.

“/etc/init.d/sshd restart” command will not work on centOS 7 servers. You will see the below error if you try to restart using that command.

[root@server]# /etc/init.d/sshd restart
-bash: /etc/init.d/sshd: No such file or directory
CentOS 7 servers have systemd so the commands are entirely different and these commands will not work on server with CentOS 6 and older versions. You must make sure the OS is version 7 before running the below commands.
Start openssh server in docker container

HOW TO RESTART SSH SERVICE ON CENTOS 7 / RHEL 7 server

Restart

Do the below steps to restart SSH service on CentOS 7 / Redhat 7 Servers.

1. Log into your Linux Server via SSH as ‘root’ user

2. Run the command ‘systemctl restart sshd.service’ to restart SSH

Command 1 : service sshd restart

OR

Command 2 : systemctl restart sshd.service

root@server [~]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service

root@server [~]# systemctl restart sshd.service
root@server [~]#

HOW TO CHECK STATUS OF SSH SERVICE ON CentOS 7 / RHEL 7 server

The below commands can be used to check the current status of SSH service, it will show whether the service is active or inactive.

1. Log into your Linux server as ‘root’

2. Run the Command ‘systemctl status sshd.service’ to check status of SSH service.

Command 1 : service sshd status

OR

Command 2 : systemctl status sshd.service

root@server [~]# systemctl status sshd.service
* sshd.service – OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2016-04-24 20:14:10 EDT; 1min 10s ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 2881 (sshd)
CGroup: /system.slice/sshd.service
`-2881 /usr/sbin/sshd -D

Apr 24 20:14:10 server systemd[1]: Started OpenSSH server daemon.
Apr 24 20:14:10 server systemd[1]: Starting OpenSSH server daemon…
Apr 24 20:14:10 server sshd[2881]: Server listening on 0.0.0.0 port 22.
Apr 24 20:14:10 server sshd[2881]: Server listening on :: port 22.

Active: inactive (dead) —> If the status shows “inactive (dead)” then it means SSH service is not running on this server

Active: active (running) —> If the status is “active (running)”, it means SSH service is running fine on this server

HOW TO START SSH SERVICE ON CENTOS 7 / REDHAT 7 SERVERS

Run the below command to start SSH service (if the service is not running)

1. Log into Linux server as root user

2. Run the below command to start SSH service

Command 1 : systemctl start sshd.service

OR

Command 2 : service sshd start

HOW TO STOP SSH SERVICE ON CENTOS 7 / REDHAT 7 SERVERS

Run the command ‘systemctl stop sshd.service’ to restart SSH service.

NOTE : The below commands will stop sshd service on your server and you might get disconnected from SSH. Run this command only if you have console access so that you can start the service.

Start Openssh Server Kali

Command 1 : service sshd stop

OR

Command 2 : systemctl stop sshd.service

root@server [/]# systemctl stop sshd.service

OR

root@server [/]# service sshd stop
Redirecting to /bin/systemctl stop sshd.service

In the below server you can see that process ID of SSH service is 221572, killing this process will stop SSH service and you will get disconnected from the server.
[root@server /]# ps aux | grep ssh

Start Openssh Server Windows

root 221572 0.0 0.0 64348 1180 ? Ss Jan26 0:55 /usr/sbin/ssh

Command to kill the above SSH process : kill -9 221572

Restart Openssh Serverchkconfig commands will not work on centOS 7 servers so you must use the below commands to enable and disable the SSH service in the runlevel. Restart Openssh Server

Enable SSH service : systemctl enable sshd

Disable SSH service : systemctl disable sshd

Restart Openssh Server

Start Openssh Server

Run the below commands to check whether SSH service is enabled and active

[root@server ~]# systemctl is-failed sshd.service
active

Restart Openssh-server

[root@server ~]# systemctl is-active sshd.service
active

How To Restart Openssh-server

[root@server ~]# systemctl is-enabled sshd.service
enabled