A Windows Guy in a Linux World: Setting up SSH Command in Linux

choubertsprojects

The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

SSH is a command-line tool for secure remote connections to network devices, primarily over the internet. This tutorial is meant as an introduction on how to set up SSH key generation and authentication in Linux Mint 18. It includes some of the basic uses you might want to do with SSH in everyday work or at home.

The “windows ssh to linux command line” is a tutorial that explains how to set up SSH Command in Linux.

A Windows Guy in a Linux World: Setting up SSH Command in Linux

Linux and Windows were formerly bitter foes, but now days they get along a lot better. In reality, SSH is now available natively in Windows as both a client and a server. What should you do if you’re a Windows administrator who also needs to handle Linux machines? In Linux, you become acclimated to the SSH command (Secure Shell).

This is the fourth installment of the blog series A Windows Guy in a Linux World. Check out Part I, Part II, and Part III if you want to learn more about common Linux topics.

You’ll discover how to activate SSH in Linux and how to configure your Windows SSH client to connect to remote Linux servers in this article.

Note that OpenSUSE Linux will be used in all of the examples.

Getting Out of the Desktop Environment

The instruction advocated utilizing the KDE desktop environment in the first part of this series. While setting up OpenSUSE, you may have seen another appealing option: the OpenSUSE server edition.

OpenSUSE Server EditionOpenSUSE Server Edition

If you’ve installed the server version of most Linux distributions (including OpenSUSE), you’ve probably realized that there’s no desktop at all. Most prominent distributions’ Server editions (such as OpenSUSE, Ubuntu Server, and CentOS) are similar to Windows Server Core in that they lack a desktop.

Understanding the CLI and SSH is required to comprehend why the desktop is often eschewed in the Linux culture.

SSH: The Remote Management Gold Standard

SSH is a client-server system, like many other remote administration protocols. A client connects to a server via the network and enables you to perform commands remotely (or even transfer files). When it comes to remotely controlling Linux, SSH is the de facto standard.

Command-line administration tools dominate the Linux server environment because SSH has been around for a long time and is well integrated in the Linux ecosystem. The majority of Linux server distributions lack a graphical user interface.

In Linux, Using SSH Commands

Enough with the babbling. Let’s have a look at what SSH can achieve by turning it on in OpenSUSE Linux. Use the YaST package manager to do this. To use SSH with YaST on OpenSUSE, follow these steps:

  1. If you installed the KDE Desktop Manager while installing OpenSUSE, go to the start menu, enter terminal, and choose Konsole.
  2. Open YaST in the terminal by typing sudo yast.
  3. To begin, go to YaST, then down to system, then over to services manager, and click Enter.
  4. To start the SSH service, arrow down to sshd and hit alt+s.
  5. To change the start mode from manual to on boot, press alt+r. This ensures that the SSH server service is launched even if the computer is rebooted.
  6. To accept and apply the changes, press alt+o.

These processes are shown in the video below.

To enable SSH, use YaST from the command line.To enable SSH, use YaST from the command line.

SSH Access Through the Firewall

Almost every Linux distribution, like Windows, comes with a firewall to safeguard it. The firewall in OpenSUSE may be found here. Allowing remote access to the SSH service from Windows requires allowing it past the firewall. To do so, follow these steps:

  1. Still in the terminal, type sudo yast to restart YaST.
  2. To continue, arrow down to Security and Users, then arrow over to Firewall and hit Enter.
  3. Navigate to Zones –> Public and arrow over to the Services—Ports pane on the right.
  4. ssh can be found in the services by arrowing down.
  5. To add the selection, hit alt+d after selecting ssh with the spacebar.
  6. To accept the modifications, press alt+a.

All of the preceding processes are shown in the diagram below.

To allow SSH via the firewall, use YaST from the command line.To allow SSH via the firewall, use YaST from the command line.

Linux, like Windows, has varying degrees of trust when it comes to applying firewall rules. Zones are the names given to these levels. By default, Windows has three zones: public, work, and private. There are many more in Linux, but it defaults to the public zone.

Using Windows to connect to Linux

Fortunately, Windows 10 now includes an SSH client. To connect to a Linux computer, open a command prompt (cmd) or a PowerShell terminal and provide the username and IP address or hostname.

> ssh <username>@<ip address>

The SSH client should prompt you to accept a fingerprint if everything works correctly. A fingerprint is a unique identifier that ensures the destination IP address has not been hijacked.

You may still SSH to your Linux server if you’re using Windows 7. All you have to do now is download the Microsoft SSH client from this link. This SSH client is the same as the one used by Windows 10.

You’re connected to your server after you press yes and enter your password! You may now utilize the command line in the same way that we would if we were using a terminal on the computer.

SSH (default port 22) should not be exposed to the Internet through your router. Bots are continually scouring the Internet for open SSH ports. When a bot discovers an open port, it will begin spamming passwords in an attempt to brute force their way in.

Using SSH with Windows and enabling mouse support

The absence of mouse functionality is one of the major disadvantages of using the native Windows 10 SSH client (at least at the time of this writing). As you may recall from a recent blog post, you cannot use a mouse in midnight commander.

Fortunately, as of version eight of the OpenSSH Windows client, mouse functionality is available! Let’s get this client up and running.

  1. Download the most recent version of OpenSSH-Win64 from here and extract the zip file that results. It is assumed that you have extracted it to DownloadsOpenSSH-Win64 in the tutorial.
  2. Navigate to Downloads on a PowerShell terminal. Downloads for OpenSSH-Win64 with cd OpenSSH-Win64.
  3. Run.ssh -V to see what version of the SSH client you’re using. The version should be 8.1.0.0-p1 at the time of authoring this tutorial.
  4. SSH into your Linux server by using .ssh <user>@<ip>.
  5. Once you’ve signed in, run mc to run midnight commander to see whether you can use a mouse.

All of the preceding processes are shown in the diagram below.

Using a Different SSH Client than the Default

You may use the new version on a more permanent basis, but you’ll have to override Windows 10’s default SSH client. This guarantees that the updated version (with mouse support) is utilized anytime you run ssh from the command line.

Assuming you’ve extracted the client to the DownloadsOpenSSH-Win64 folder, continue.

  1. Place the OpenSSH-Win64 folder in a permanent location of your choosing. C:userspublicOpenSSH-Win64 will be used in this tutorial.
  2. Open System from the control panel or go to Start > Run and enter sysdm.cpl.
  3. Select Environment Variables from the Advanced menu.
  4. Path may be found under System Variables.
  5. To add a new path, click New and provide the folder path to the SSH client (C:userspublicOpenSSH-Win64 in this case).
  6. Move it above the percent SystemRoot percent system32 folder by clicking Move Up. This ensures that Windows looks here first when you write ssh on the command line.
  7. ssh -V should be executed from a PowerShell console. You should see 8.1.0.0-p as the version.

These stages are outlined in the next section.

Using a Different SSH Client than the DefaultUsing a Different SSH Client than the Default

It might be dangerous to prioritize a folder above percent SystemRoot percent system32. If someone has access to your computer, they may place a virus in the OpenSSH-Win64 folder and call it cd.exe or another Windows application.

Anyone other than administrators should be able to view the OpenSSH-Win64 folder.

  1. Right-click the OpenSSH-Win64 folder and choose Properties from the context menu.
  2. Click the Advanced option under the Security tab.
  3. To enable custom folder rights and prevent parent folders from overriding permissions in the OpenSSH-Win64 folder, choose Disable inheritance.
  4. Select Add, locate the Administrators group, and provide them complete access.
  5. Add a new group, Everyone, and grant them read-only rights.
  6. To apply these adjustments to all files in the OpenSSH-Win64 folder, choose the Replace all child object permission option and click Apply.
  7. Create a new file in the OpenSSH-Win64 folder to test these permissions. An Administrator prompt should be required on Windows.

All of the preceding processes are shown in the diagram below.

The OpenSSH-Win64 folder is restricted.The OpenSSH-Win64 folder is restricted.

Using Tmux to Manage Disconnected Sessions

What an annoyance! You’re halfway through a long-running command through SSH when the Internet goes down. You have no idea what condition the Linux server is in now! Is that command complete? How are you going to get it back?

Disconnected sessions are a genuine problem with SSH, and fortunately, there is a simple remedy. A terminal multiplexer is required (tmux).

Tmux is the acronym for terminal multiplexer, as well as the name of the software.

Tmux is an SSH session manager. If you are disconnected, it “holds on” to the session and continues it running in the background. You may return to that session at a later time, or you can establish additional sessions and switch between them.

To use tmux to handle disconnected sessions, follow these steps:

  1. Run sudo zypper install -y tmux in the Linux terminal to download and install the tmux software, as shown below:

You may also use the YaST to get the tmux tool.

Tmux Utility is a program that allows you to combine many filesTmux Utility is a program that allows you to combine many files

The command-line package manager in most Linux distributions is distinct. Zypper is used by OpenSUSE. Pacman is used by Arch. Ubuntu makes use of the apt package manager. Dnf and yum are used by Red Hat. Thankfully, the syntax for all of these package managers is very same.

2. Open a PowerShell terminal on your Windows machine and SSH into your Linux server. The tutorial will use the username homelab and the IP address 192.168.134.169 for the Linux server.

ssh <username>@<ip address>

3. Once connected, execute tmux to open tmux. A green bar should appear at the bottom.

4. Execute a command that produces text. It makes no difference what it is. neofetch is used in this tutorial. You may also use ls.

5. Close PowerShell to disconnect the session. This action imitates quitting.

6. Use SSH to reconnect to your Linux server.

7. Now run tmux a to reconnect to the previous session. The output of the preceding ls command should still be visible. No data lost due to the disconnect, yay!

All of the preceding processes are shown in the diagram below.

Using a Tmux to Manage Disconnected SessionsUsing a Tmux to Manage Disconnected Sessions

You may find that you don’t have mouse support if you attempt running the Midnight Commander application inside of tmux. Instead, use mc -x to repair the problem.

Login with tmux enabled

Tmux will not be accessible in all SSH sessions by default. This may be changed by requiring tmux to connect to your SSH session every time you log in.

Assuming you’ve SSHed into your Linux server, do the following:

  1. Using the command mc, launch the Midnight Commander software.

2. Select the.bashrc file and press edit.

The.bashrc file is a batch (shell) script that runs every time you use the command line to log in.

3. At the bottom of the text file, paste the shell script code below.

tmux attach -t default || tmux new -s default fi if [-z “$TMUX”];

4. When asked, click quit and save.

5. Test the tmux auto-attach by detaching and reconnecting to your SSH session. A green bar should appear at the bottom, indicating that you are connected to a tmux session!

That’s just scraping the surface of tmux’s capabilities; it’s a very capable multitasking software. If you ask any Linux administrator what their most often used command is, they’ll most likely say tmux.

Wrap Up

The latest installment of the A Windows Guy in a Linux World blog series comes to a close now. Keep an eye on the ATA blog for the next installment!

The “code server ssh remote” is a command that allows you to SSH into your Linux machine. This can be useful for setting up terminal services.

Related Tags

  • ssh to linux from windows powershell
  • ssh windows 10 command line
  • remote ssh allowlocalserverdownload
  • vscode copy file from remote ssh
  • setting up ssh host initializing vscode-server

Table of Content