OpenSSH/Configuring - Community Help Wiki (2024)

Parent page: Internet and Networking >> SSH

Contents

  1. Introduction
  2. Disable Password Authentication
  3. Disable Forwarding
  4. Specify Which Accounts Can Use SSH
  5. Rate-limit the connections
  6. Log More Information
  7. Display a Banner
  8. Troubleshooting

Once you have installed an OpenSSH server,

sudo apt-get install openssh-server 

you will need to configure it by editing the sshd_config file in the /etc/ssh directory.

OpenSSH/Configuring - Community Help Wiki (1)

sshd_config is the configuration file for the OpenSSH server. ssh_config is the configuration file for the OpenSSH client. Make sure not to get them mixed up.

First, make a backup of your sshd_config file by copying it to your home directory, or by making a read-only copy in /etc/ssh by doing:

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaultssudo chmod a-w /etc/ssh/sshd_config.factory-defaults

Creating a read-only backup in /etc/ssh means you'll always be able to find a known-good configuration when you need it.

Once you've backed up your sshd_config file, you can make changes with any text editor, for example;

sudo gedit /etc/ssh/sshd_config

runs the standard text editor in Ubuntu 12.04 or more recent. For older versions replace "sudo" with "gksudo". Once you've made your changes (see the suggestions in the rest of this page), you can apply them by saving the file then doing:

sudo restart ssh

If you get the error, "Unable to connect to Upstart", restart ssh with the following:

sudo systemctl restart ssh

Configuring OpenSSH means striking a balance between security and ease-of-use. Ubuntu's default configuration tries to be as secure as possible without making it impossible to use in common use cases. This page discusses some changes you can make, and how they affect the balance between security and ease-of-use. When reading each section, you should decide what balance is right for your specific situation.

Because a lot of people with SSH servers use weak passwords, many online attackers will look for an SSH server, then start guessing passwords at random. An attacker can try thousands of passwords in an hour, and guess even the strongest password given enough time. The recommended solution is to use SSH keys instead of passwords. To be as hard to guess as a normal SSH key, a password would have to contain 634 random letters and numbers. If you'll always be able to log in to your computer with an SSH key, you should disable password authentication altogether.

If you disable password authentication, it will only be possible to connect from computers you have specifically approved. This massively improves your security, but makes it impossible for you to connect to your own computer from a friend's PC without pre-approving the PC, or from your own laptop when you accidentally delete your key.

It's recommended to disable password authentication unless you have a specific reason not to.

To disable password authentication, look for the following line in your sshd_config file:

#PasswordAuthenticationyes

replace it with a line that looks like this:

Once you have saved the file and restarted your SSH server, you shouldn't even be asked for a password when you log in.

By default, you can tunnel network connections through an SSH session. For example, you could connect over the Internet to your PC, tunnel a remote desktop connection, and access your desktop. This is known as "port forwarding".

By default, you can also tunnel specific graphical applications through an SSH session. For example, you could connect over the Internet to your PC and run nautilus"file://$HOME" to see your PC's home folder. This is known as "X11 forwarding".

While both of these are very useful, they also give more options to an attacker who has already guessed your password. Disabling these options gives you a little security, but not as much as you'd think. With access to a normal shell, a resourceful attacker can replicate both of these techniques and a specially-modified SSH client.

It's only recommended to disable forwarding if you also use SSH keys with specified commands.

To disable forwarding, look for the following lines in your sshd_config:

AllowTcpForwardingyes

X11Forwardingyes

and replace them with:

AllowTcpForwardingno

X11Forwardingno

If either of the above lines don't exist, just add the replacement to the bottom of the file. You can disable each of these independently if you prefer.

You can explicitly allow or deny access for certain users or groups. For example, if you have a family PC where most people have weak passwords, you might want to allow SSH access just for yourself.

Allowing or denying SSH access for specific users can significantly improve your security if users with poor security practices don't need SSH access.

It's recommended to specify which accounts can use SSH if only a few users want (not) to use SSH.

To allow only the users Fred and Wilma to connect to your computer, add the following line to the bottom of the sshd_config file:

AllowUsersFredWilma

To allow everyone except the users Dino and Pebbles to connect to your computer, add the following line to the bottom of the sshd_config file:

DenyUsersDinoPebbles

It's possible to create very complex rules about who can use SSH - you can allow or deny specific groups of users, or users whose names match a specific pattern, or who are logging in from a specific location. For more details about how to create complex rules, see the sshd_config man page

It's possible to limit the rate at which one IP address can establish new SSH connections by configuring the uncomplicated firewall (ufw). If an IP address is tries to connect more than 10 times in 30 seconds, all the following attempts will fail since the connections will be DROPped. The rule is added to the firewall by running a single command:

sudo ufw limit ssh

On a single-user or low-powered system, such as a laptop, the number of total simultaneous pending (not yet authorized) login connections to the system can also be limited. This example will allow two pending connections. Between the third and tenth connection the system will start randomly dropping connections from 30% up to 100% at the tenth simultaneous connection. This should be set in sshd_config.

MaxStartups2:30:10

In a multi-user or server environment, these numbers should be set significantly higher depending on resources and demand to alleviate denial-of-access attacks. Setting a lower the login grace time (time to keep pending connections alive while waiting for authorization) can be a good idea as it frees up pending connections quicker but at the expense of convenience.

LoginGraceTime30

By default, the OpenSSH server logs to the AUTH facility of syslog, at the INFO level. If you want to record more information - such as failed login attempts - you should increase the logging level to VERBOSE.

It's recommended to log more information if you're curious about malicious SSH traffic.

To increase the level, find the following line in your sshd_config:

LogLevelINFO

and change it to this:

LogLevelVERBOSE

Now all the details of ssh login attempts will be saved in your /var/log/auth.log file.

If you have started using a different port, or if you think your server is well-enough hidden not to need much security, you should increase your logging level and examine your auth.log file every so often. If you find a significant number of spurious login attempts, then your computer is under attack and you need more security.

Whatever security precautions you've taken, you might want to set the logging level to VERBOSE for a week, and see how much spurious traffic you get. It can be a sobering experience to see just how much your computer gets attacked.

If you want to try to scare novice attackers, it can be funny to display a banner containing legalese. This doesn't add any security, because anyone that's managed to break in won't care about a "no trespassing" sign--but it might give a bad guy a chuckle.

To add a banner that will be displayed before authentication, find this line:

#Banner/etc/issue.net

and replace it with:

Banner/etc/issue.net

This will display the contents of the /etc/issue.net file, which you should edit to your taste. If you want to display the same banner to SSH users as to users logging in on a local console, replace the line with:

Banner/etc/issue

To edit the banner itself try

sudo gedit /etc/issue.net

Here is an example for what you might put in an issue or issue.net file and you could just copy&paste this in:

*************************************************************************** NOTICE TO USERSThis computer system is the private property of its owner, whetherindividual, corporate or government. It is for authorized use only.Users (authorized or unauthorized) have no explicit or implicitexpectation of privacy.Any or all uses of this system and all files on this system may beintercepted, monitored, recorded, copied, audited, inspected, anddisclosed to your employer, to authorized site, government, and lawenforcement personnel, as well as authorized officials of governmentagencies, both domestic and foreign.By using this system, the user consents to such interception, monitoring,recording, copying, auditing, inspection, and disclosure at thediscretion of such personnel or officials. Unauthorized or improper useof this system may result in civil and criminal penalties andadministrative or disciplinary action, as appropriate. By continuing touse this system you indicate your awareness of and consent to these termsand conditions of use. LOG OFF IMMEDIATELY if you do not agree to theconditions stated in this warning.****************************************************************************

Once you have finished editing sshd_config, make sure to save your changes before restarting your SSH daemon.

First, check that your SSH daemon is running:

ps -A | grep sshd

This command should produce a line like this:

<some number> ? 00:00:00 sshd

If there is no line, your SSH daemon is not running. If it is, you should next check that it's listening for incoming connections:

sudo ss -lnp | grep sshd

This command should produce a line that looks like one of these:

0 128 :::22 :::* users:(("sshd",16893,4))0 128 *:22 *:* users:(("sshd",16893,3))

If there is more than one line, in particular with a port number different than 22, then your SSH daemon is listening on more than one port - you might want to go back and delete some Port lines in your sshd_config. If there are no lines, your SSH daemon is not listening on any ports, so you need to add at least one Port line. If the line specifies something other than "*:22" ([::]:22 is IPv6), then your SSH daemon is listening on a non-standard port or address, which you might want to fix.

Next, try logging in from your own computer:

ssh -v localhost

This will print a lot of debugging information, and will try to connect to your SSH server. You should be prompted to type your password, and you should get another command-line when you type your password in. If this works, then your SSH server is listening on the standard SSH port. If you have set your computer to listen on a non-standard port, then you will need to go back and comment out (or delete) a line in your configuration that reads Port22. Otherwise, your SSH server has been configured correctly.

To leave the SSH command-line, type:

exit

If you have a local network (such as a home or office network), next try logging in from one of the other computers on your network. If nothing happens, you might need to tell your computer's firewall to allow connections on port 22 (or from the non-standard port you chose earlier).

Finally, try logging in from another computer elsewhere on the Internet - perhaps from work (if your computer is at home) or from home (if your computer is at your work). If you can't access your computer this way, you might need to tell your router's firewall to allow connections from port 22, and might also need to configure Network Address Translation.

OpenSSH/Configuring - Community Help Wiki (2024)
Top Articles
The 1 percent club: In India, ₹1.4 cr can make the cut but in US you need 30x more | Business Insider India
What is the Best Way to Clean and Store Reusable Water Bottles?
Omega Pizza-Roast Beef -Seafood Middleton Menu
Mybranch Becu
Top 11 Best Bloxburg House Ideas in Roblox - NeuralGamer
Kem Minnick Playboy
Ghosted Imdb Parents Guide
Georgia Vehicle Registration Fees Calculator
Jonathan Freeman : "Double homicide in Rowan County leads to arrest" - Bgrnd Search
Richard Sambade Obituary
Ub Civil Engineering Flowsheet
Doby's Funeral Home Obituaries
Regular Clear vs Low Iron Glass for Shower Doors
4Chan Louisville
Power Outage Map Albany Ny
Blue Beetle Showtimes Near Regal Swamp Fox
Binghamton Ny Cars Craigslist
Industry Talk: Im Gespräch mit den Machern von Magicseaweed
Huge Boobs Images
Wizard Build Season 28
Harem In Another World F95
Exterior insulation details for a laminated timber gothic arch cabin - GreenBuildingAdvisor
Theater X Orange Heights Florida
Japanese Mushrooms: 10 Popular Varieties and Simple Recipes - Japan Travel Guide MATCHA
Bay Area Craigslist Cars For Sale By Owner
At 25 Years, Understanding The Longevity Of Craigslist
Reserve A Room Ucla
Funky Town Gore Cartel Video
Greyson Alexander Thorn
Craigslist Free Puppy
Japanese Pokémon Cards vs English Pokémon Cards
Appleton Post Crescent Today's Obituaries
Bee And Willow Bar Cart
2016 Honda Accord Belt Diagram
Wednesday Morning Gifs
Tenant Vs. Occupant: Is There Really A Difference Between Them?
Linabelfiore Of
Ticketmaster Lion King Chicago
Robeson County Mugshots 2022
Priscilla 2023 Showtimes Near Consolidated Theatres Ward With Titan Luxe
Craigslist Putnam Valley Ny
Jack In The Box Menu 2022
Bill Manser Net Worth
Pekin Soccer Tournament
Devotion Showtimes Near Showplace Icon At Valley Fair
Aurora Southeast Recreation Center And Fieldhouse Reviews
Wzzm Weather Forecast
Tyrone Unblocked Games Bitlife
Mawal Gameroom Download
Fahrpläne, Preise und Anbieter von Bookaway
Suzanne Olsen Swift River
Lux Nails & Spa
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 5913

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.