{"id":898,"date":"2016-01-29T00:10:47","date_gmt":"2016-01-29T07:10:47","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=898"},"modified":"2022-11-22T05:14:51","modified_gmt":"2022-11-22T05:14:51","slug":"sshopensshconfiguring","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2016\/01\/29\/sshopensshconfiguring\/","title":{"rendered":"SSH\/OpenSSH\/Configuring"},"content":{"rendered":"<h1 id=\"Introduction\">Introduction<\/h1>\n<p class=\"line874\">Once you have installed an OpenSSH server, <span id=\"line-8\" class=\"anchor\"><\/span><span id=\"line-9\" class=\"anchor\"><\/span><span id=\"line-10\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1\" class=\"anchor\">sudo apt-get update \n<\/span>sudo apt-get install openssh-server\n<code>sudo ufw allow 22<\/code><\/pre>\n<p class=\"line862\">you will need to configure it by editing the <tt class=\"backtick\">sshd_config<\/tt> file in the <tt class=\"backtick\">\/etc\/ssh<\/tt> directory.<span id=\"line-12\" class=\"anchor\"><\/span><span id=\"line-13\" class=\"anchor\"><\/span><span id=\"line-14\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><img decoding=\"async\" class=\"attachment\" title=\"IconsPage\/tip.png\" src=\"https:\/\/help.ubuntu.com\/community\/IconsPage?action=AttachFile&amp;do=get&amp;target=tip.png\" alt=\"IconsPage\/tip.png\"><\/p>\n<\/td>\n<td>\n<p class=\"line891\"><tt class=\"backtick\">sshd_config<\/tt> is the configuration file for the OpenSSH <em>server<\/em>. <tt class=\"backtick\">ssh_config<\/tt> is the configuration file for the OpenSSH <em>client<\/em>. Make sure not to get them mixed up.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line862\">First, make a backup of your <tt class=\"backtick\">sshd_config<\/tt> file by copying it to your home directory, or by making a read-only copy in <tt class=\"backtick\">\/etc\/ssh<\/tt> by doing:<span id=\"line-17\" class=\"anchor\"><\/span><span id=\"line-18\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-1\" class=\"anchor\"><\/span>sudo cp \/etc\/ssh\/sshd_config \/etc\/ssh\/sshd_config.factory-defaults\n<span id=\"line-2\" class=\"anchor\"><\/span>sudo chmod a-w \/etc\/ssh\/sshd_config.factory-defaults<\/pre>\n<p class=\"line862\">Creating a read-only backup in <tt class=\"backtick\">\/etc\/ssh<\/tt> means you&#8217;ll always be able to find a known-good configuration when you need it.<span id=\"line-24\" class=\"anchor\"><\/span><span id=\"line-25\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">Once you&#8217;ve backed up your <tt class=\"backtick\">sshd_config<\/tt> file, you can make changes with any text editor, for example; <span id=\"line-26\" class=\"anchor\"><\/span><span id=\"line-27\" class=\"anchor\"><\/span><span id=\"line-28\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-2\" class=\"anchor\"><\/span>sudo gedit \/etc\/ssh\/sshd_config<\/pre>\n<p class=\"line874\">runs the standard text editor in Ubuntu 12.04 or more recent. For older versions replace &#8220;sudo&#8221; with &#8220;gksudo&#8221;. Once you&#8217;ve made your changes (see the suggestions in the rest of this page), you can apply them by saving the file then doing:<span id=\"line-30\" class=\"anchor\"><\/span><span id=\"line-31\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-3\" class=\"anchor\"><\/span>sudo restart ssh<\/pre>\n<p class=\"line874\">If you get the error, &#8220;Unable to connect to Upstart&#8221;, restart ssh with the following:<span id=\"line-36\" class=\"anchor\"><\/span><span id=\"line-37\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-4\" class=\"anchor\"><\/span>sudo systemctl restart ssh<\/pre>\n<p class=\"line874\">Configuring OpenSSH means striking a balance between security and ease-of-use. Ubuntu&#8217;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.<span id=\"line-42\" class=\"anchor\"><\/span><span id=\"line-43\" class=\"anchor\"><\/span><\/p>\n<h1 id=\"Disable_Password_Authentication\">Disable Password Authentication<\/h1>\n<p class=\"line862\">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 <a href=\"https:\/\/help.ubuntu.com\/community\/SSH\/OpenSSH\/Keys\">SSH keys<\/a> 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&#8217;ll always be able to log in to your computer with an SSH key, you should disable password authentication altogether.<span id=\"line-47\" class=\"anchor\"><\/span><span id=\"line-48\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">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&#8217;s PC without pre-approving the PC, or from your own laptop when you accidentally delete your key.<span id=\"line-49\" class=\"anchor\"><\/span><span id=\"line-50\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\"><em>It&#8217;s recommended to disable password authentication unless you have a specific reason not to.<\/em><span id=\"line-51\" class=\"anchor\"><\/span><span id=\"line-52\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">To disable password authentication, look for the following line in your <tt class=\"backtick\">sshd_config<\/tt> file:<span id=\"line-53\" class=\"anchor\"><\/span><span id=\"line-54\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>#PasswordAuthentication&nbsp;yes<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line874\">replace it with a line that looks like this:<span id=\"line-57\" class=\"anchor\"><\/span><span id=\"line-58\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>PasswordAuthentication&nbsp;no<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line862\">Once you have saved the file and <a class=\"http\" href=\"http:\/\/www.cyberciti.biz\/faq\/howto-start-stop-ssh-server\/\">restarted your SSH server<\/a>, you shouldn&#8217;t even be asked for a password when you log in.<span id=\"line-61\" class=\"anchor\"><\/span><span id=\"line-62\" class=\"anchor\"><\/span><\/p>\n<h1 id=\"Disable_Forwarding\">Disable Forwarding<\/h1>\n<p class=\"line862\">By default, you can tunnel network connections through an SSH session. For example, you could connect over the Internet to your PC, tunnel a<a href=\"https:\/\/help.ubuntu.com\/community\/VNC\">remote desktop<\/a> connection, and access your desktop. This is known as &#8220;port forwarding&#8221;.<span id=\"line-66\" class=\"anchor\"><\/span><span id=\"line-67\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">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 <tt class=\"backtick\">nautilus&nbsp;\"file:\/\/$HOME\"<\/tt> to see your PC&#8217;s home folder. This is known as &#8220;X11 forwarding&#8221;.<span id=\"line-68\" class=\"anchor\"><\/span><span id=\"line-69\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">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&#8217;d think. With access to a normal shell, a resourceful attacker can replicate both of these techniques and a specially-modified SSH client.<span id=\"line-70\" class=\"anchor\"><\/span><span id=\"line-71\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\"><em>It&#8217;s only recommended to disable forwarding if you also use <a href=\"https:\/\/help.ubuntu.com\/community\/SSH\/OpenSSH\/Keys#keys-with-specific-commands\">SSH keys with specified commands<\/a><\/em>.<span id=\"line-72\" class=\"anchor\"><\/span><span id=\"line-73\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">To disable forwarding, look for the following lines in your <tt class=\"backtick\">sshd_config<\/tt>:<span id=\"line-74\" class=\"anchor\"><\/span><span id=\"line-75\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>AllowTcpForwarding&nbsp;yes<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>X11Forwarding&nbsp;yes<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line874\">and replace them with:<span id=\"line-80\" class=\"anchor\"><\/span><span id=\"line-81\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>AllowTcpForwarding&nbsp;no<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>X11Forwarding&nbsp;no<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line874\">If either of the above lines don&#8217;t exist, just add the replacement to the bottom of the file. You can disable each of these independently if you prefer.<span id=\"line-86\" class=\"anchor\"><\/span><span id=\"line-87\" class=\"anchor\"><\/span><\/p>\n<h1 id=\"Specify_Which_Accounts_Can_Use_SSH\">Specify Which Accounts Can Use SSH<\/h1>\n<p class=\"line874\">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.<span id=\"line-90\" class=\"anchor\"><\/span><span id=\"line-91\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">Allowing or denying SSH access for specific users can significantly improve your security if users with poor security practices don&#8217;t need SSH access.<span id=\"line-92\" class=\"anchor\"><\/span><span id=\"line-93\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\"><em>It&#8217;s recommended to specify which accounts can use SSH if only a few users want (not) to use SSH.<\/em><span id=\"line-94\" class=\"anchor\"><\/span><span id=\"line-95\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">To allow only the users <tt class=\"backtick\">Fred<\/tt> and <tt class=\"backtick\">Wilma<\/tt> to connect to your computer, add the following line to the bottom of the <tt class=\"backtick\">sshd_config<\/tt> file:<span id=\"line-96\" class=\"anchor\"><\/span><span id=\"line-97\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>AllowUsers&nbsp;Fred&nbsp;Wilma<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line862\">To allow everyone except the users <tt class=\"backtick\">Dino<\/tt> and <tt class=\"backtick\">Pebbles<\/tt> to connect to your computer, add the following line to the bottom of the <tt class=\"backtick\">sshd_config<\/tt> file:<span id=\"line-100\" class=\"anchor\"><\/span><span id=\"line-101\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>DenyUsers&nbsp;Dino&nbsp;Pebbles<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line862\">It&#8217;s possible to create very complex rules about who can use SSH &#8211; 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 <a class=\"http\" href=\"http:\/\/manpages.ubuntu.com\/manpages\/hardy\/man5\/sshd_config.5.html\">sshd_config man page<\/a><span id=\"line-104\" class=\"anchor\"><\/span><span id=\"line-105\" class=\"anchor\"><\/span><\/p>\n<h1 id=\"Rate-limit_the_connections\">Rate-limit the connections<\/h1>\n<p class=\"line862\">It&#8217;s possible to limit the rate at which one IP address can establish new SSH connections by <a href=\"https:\/\/help.ubuntu.com\/community\/UFW\">configuring the uncomplicated firewall<\/a> (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:<span id=\"line-107\" class=\"anchor\"><\/span><span id=\"line-108\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-5\" class=\"anchor\"><\/span>sudo ufw limit ssh<\/pre>\n<p class=\"line862\">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 <tt class=\"backtick\">sshd_config<\/tt>.<span id=\"line-113\" class=\"anchor\"><\/span><span id=\"line-114\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>MaxStartups&nbsp;2:30:10<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line874\">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.<span id=\"line-117\" class=\"anchor\"><\/span><span id=\"line-118\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>LoginGraceTime&nbsp;30<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h1 id=\"Log_More_Information\">Log More Information<\/h1>\n<p class=\"line874\">By default, the OpenSSH server logs to the AUTH facility of syslog, at the INFO level. If you want to record more information &#8211; such as failed login attempts &#8211; you should increase the logging level to VERBOSE.<span id=\"line-124\" class=\"anchor\"><\/span><span id=\"line-125\" class=\"anchor\"><\/span><\/p>\n<p class=\"line867\"><em>It&#8217;s recommended to log more information if you&#8217;re curious about malicious SSH traffic.<\/em><span id=\"line-126\" class=\"anchor\"><\/span><span id=\"line-127\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">To increase the level, find the following line in your <tt class=\"backtick\">sshd_config<\/tt>:<span id=\"line-128\" class=\"anchor\"><\/span><span id=\"line-129\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>LogLevel&nbsp;INFO<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line874\">and change it to this:<span id=\"line-132\" class=\"anchor\"><\/span><span id=\"line-133\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>LogLevel&nbsp;VERBOSE<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line862\">Now all the details of <tt class=\"backtick\">ssh<\/tt> login attempts will be saved in your <tt class=\"backtick\">\/var\/log\/auth.log<\/tt> file.<span id=\"line-136\" class=\"anchor\"><\/span><span id=\"line-137\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">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 <tt class=\"backtick\">auth.log<\/tt> 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.<span id=\"line-138\" class=\"anchor\"><\/span><span id=\"line-139\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">Whatever security precautions you&#8217;ve taken, you might want to set the logging level to <tt class=\"backtick\">VERBOSE<\/tt> 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.<span id=\"line-140\" class=\"anchor\"><\/span><span id=\"line-141\" class=\"anchor\"><\/span><\/p>\n<h1 id=\"Display_a_Banner\">Display a Banner<\/h1>\n<p class=\"line874\">If you want to try to scare novice attackers, it can be funny to display a banner containing legalese. This doesn&#8217;t add any security, because anyone that&#8217;s managed to break in won&#8217;t care about a &#8220;no trespassing&#8221; sign&#8211;but it might give a bad guy a chuckle.<span id=\"line-144\" class=\"anchor\"><\/span><span id=\"line-145\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">To add a banner that will be displayed before authentication, find this line:<span id=\"line-146\" class=\"anchor\"><\/span><span id=\"line-147\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>#Banner&nbsp;\/etc\/issue.net<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line874\">and replace it with:<span id=\"line-150\" class=\"anchor\"><\/span><span id=\"line-151\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>Banner&nbsp;\/etc\/issue.net<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line862\">This will display the contents of the <tt class=\"backtick\">\/etc\/issue.net<\/tt> 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:<span id=\"line-154\" class=\"anchor\"><\/span><span id=\"line-155\" class=\"anchor\"><\/span><\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<p class=\"line891\"><strong><tt>Banner&nbsp;\/etc\/issue<\/tt><\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"line874\">To edit the banner itself try <span id=\"line-158\" class=\"anchor\"><\/span><span id=\"line-159\" class=\"anchor\"><\/span><span id=\"line-160\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-6\" class=\"anchor\"><\/span>sudo gedit \/etc\/issue.net<\/pre>\n<p class=\"line862\">Here is an example for what you might put in an <tt class=\"backtick\">issue<\/tt> or <tt class=\"backtick\">issue.net<\/tt> file and you could just copy&amp;paste this in:<span id=\"line-163\" class=\"anchor\"><\/span><span id=\"line-164\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-7\" class=\"anchor\"><\/span>***************************************************************************\n<span id=\"line-2-1\" class=\"anchor\"><\/span>                            NOTICE TO USERS\n<span id=\"line-3\" class=\"anchor\"><\/span>\n<span id=\"line-4\" class=\"anchor\"><\/span>\n<span id=\"line-5\" class=\"anchor\"><\/span>This computer system is the private property of its owner, whether\n<span id=\"line-6\" class=\"anchor\"><\/span>individual, corporate or government.  It is for authorized use only.\n<span id=\"line-7\" class=\"anchor\"><\/span>Users (authorized or unauthorized) have no explicit or implicit\n<span id=\"line-8\" class=\"anchor\"><\/span>expectation of privacy.\n<span id=\"line-9\" class=\"anchor\"><\/span>\n<span id=\"line-10\" class=\"anchor\"><\/span>Any or all uses of this system and all files on this system may be\n<span id=\"line-11\" class=\"anchor\"><\/span>intercepted, monitored, recorded, copied, audited, inspected, and\n<span id=\"line-12\" class=\"anchor\"><\/span>disclosed to your employer, to authorized site, government, and law\n<span id=\"line-13\" class=\"anchor\"><\/span>enforcement personnel, as well as authorized officials of government\n<span id=\"line-14\" class=\"anchor\"><\/span>agencies, both domestic and foreign.\n<span id=\"line-15\" class=\"anchor\"><\/span>\n<span id=\"line-16\" class=\"anchor\"><\/span>By using this system, the user consents to such interception, monitoring,\n<span id=\"line-17\" class=\"anchor\"><\/span>recording, copying, auditing, inspection, and disclosure at the\n<span id=\"line-18\" class=\"anchor\"><\/span>discretion of such personnel or officials.  Unauthorized or improper use\n<span id=\"line-19\" class=\"anchor\"><\/span>of this system may result in civil and criminal penalties and\n<span id=\"line-20\" class=\"anchor\"><\/span>administrative or disciplinary action, as appropriate. By continuing to\n<span id=\"line-21\" class=\"anchor\"><\/span>use this system you indicate your awareness of and consent to these terms\n<span id=\"line-22\" class=\"anchor\"><\/span>and conditions of use. LOG OFF IMMEDIATELY if you do not agree to the\n<span id=\"line-23\" class=\"anchor\"><\/span>conditions stated in this warning.\n<span id=\"line-24\" class=\"anchor\"><\/span>\n<span id=\"line-25\" class=\"anchor\"><\/span>****************************************************************************<\/pre>\n<h1 id=\"Troubleshooting\">Troubleshooting<\/h1>\n<p class=\"line862\">Once you have finished editing <tt class=\"backtick\">sshd_config<\/tt>, make sure to save your changes before restarting your SSH daemon.<span id=\"line-195\" class=\"anchor\"><\/span><span id=\"line-196\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">First, check that your SSH daemon is running:<span id=\"line-197\" class=\"anchor\"><\/span><span id=\"line-198\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-8\" class=\"anchor\"><\/span>ps -A | grep sshd<\/pre>\n<p class=\"line874\">This command should produce a line like this:<span id=\"line-203\" class=\"anchor\"><\/span><span id=\"line-204\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-9\" class=\"anchor\"><\/span>&lt;some number&gt; ?        00:00:00 sshd<\/pre>\n<p class=\"line874\">If there is no line, your SSH daemon is not running. If it is, you should next check that it&#8217;s listening for incoming connections:<span id=\"line-209\" class=\"anchor\"><\/span><span id=\"line-210\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-10\" class=\"anchor\"><\/span>sudo ss -lnp | grep sshd<\/pre>\n<p class=\"line874\">This command should produce a line that looks like one of these:<span id=\"line-215\" class=\"anchor\"><\/span><span id=\"line-216\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-11\" class=\"anchor\"><\/span>0  128  :::22  :::*  users:((\"sshd\",16893,4))\n<span id=\"line-2-2\" class=\"anchor\"><\/span>0  128   *:22   *:*  users:((\"sshd\",16893,3))<\/pre>\n<p class=\"line862\">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 &#8211; you might want to go back and delete some <tt class=\"backtick\">Port<\/tt> lines in your <tt class=\"backtick\">sshd_config<\/tt>. If there are no lines, your SSH daemon is not listening on any ports, so you need to add at least one <tt class=\"backtick\">Port<\/tt> line. If the line specifies something other than &#8220;*:22&#8221; ([::]:22 is IPv6), then your SSH daemon is listening on a non-standard port or address, which you might want to fix.<span id=\"line-222\" class=\"anchor\"><\/span><span id=\"line-223\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">Next, try logging in from your own computer:<span id=\"line-224\" class=\"anchor\"><\/span><span id=\"line-225\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-12\" class=\"anchor\"><\/span>ssh -v localhost<\/pre>\n<p class=\"line862\">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 <tt class=\"backtick\">Port&nbsp;22<\/tt>. Otherwise, your SSH server has been configured correctly.<span id=\"line-230\" class=\"anchor\"><\/span><span id=\"line-231\" class=\"anchor\"><\/span><\/p>\n<p class=\"line874\">To leave the SSH command-line, type:<span id=\"line-232\" class=\"anchor\"><\/span><span id=\"line-233\" class=\"anchor\"><\/span><\/p>\n<pre><span id=\"line-1-13\" class=\"anchor\"><\/span>exit<\/pre>\n<p class=\"line874\">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&#8217;s firewall to allow connections on port 22 (or from the non-standard port you chose earlier).<span id=\"line-238\" class=\"anchor\"><\/span><span id=\"line-239\" class=\"anchor\"><\/span><\/p>\n<p class=\"line862\">Finally, try logging in from another computer elsewhere on the Internet &#8211; perhaps from work (if your computer is at home) or from home (if your computer is at your work). If you can&#8217;t access your computer this way, you might need to tell your router&#8217;s firewall to allow connections from port 22, and might also need to configure <a href=\"https:\/\/help.ubuntu.com\/community\/ServersBehindNAT\">Network Address Translation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Once you have installed an OpenSSH server, sudo apt-get update sudo apt-get install openssh-server sudo ufw allow 22 you will need to configure it&hellip; <\/p>\n","protected":false},"author":1,"featured_media":956,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-898","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=898"}],"version-history":[{"count":1,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/898\/revisions"}],"predecessor-version":[{"id":960,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/898\/revisions\/960"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media\/956"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}