Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794
{"id":2922,"date":"2019-12-27T07:26:02","date_gmt":"2019-12-27T07:26:02","guid":{"rendered":"https:\/\/support.aklwebhost.com\/?post_type=manual_kb&p=2922"},"modified":"2019-12-27T07:26:02","modified_gmt":"2019-12-27T07:26:02","slug":"securing-ssh-on-ubuntu-14-04","status":"publish","type":"manual_kb","link":"https:\/\/support.aklwebhost.com\/knowledgebase\/securing-ssh-on-ubuntu-14-04\/","title":{"rendered":"Securing SSH on Ubuntu 14.04"},"content":{"rendered":"

After you create a new server, there are some configuration tweaks that you should make to harden the security of your server.<\/p>\n

Create a new user<\/h3>\n

As the root user, you have privileges to do anything that you want with the server – no restrictions. Because of this, it is better to\u00a0avoid using the root user account<\/strong>\u00a0for every task on your server. Let’s start by making a new user. Replace\u00a0username<\/code>\u00a0with the desired user name:<\/p>\n

adduser username\r\n<\/code><\/pre>\n

Choose a new\u00a0secure password<\/strong>\u00a0and respond to the questions accordingly (or just hit ENTER to use the default value).<\/p>\n

Giving user root privileges<\/h3>\n

New user accounts don’t have privileges outside of their home folder and cannot run commands that will alter the server (like\u00a0install<\/code>,\u00a0update<\/code>, or\u00a0upgrade<\/code>). To avoid the use of the root account, we will give the user root privileges. There are two ways of doing this:<\/p>\n

Adding user to sudo group<\/h4>\n

The easy way is to add the user to the\u00a0sudo<\/code>\u00a0group. Replace\u00a0username<\/code>\u00a0with the desired user name:<\/p>\n

adduser username sudo\r\n<\/code><\/pre>\n

This will add the user to the group\u00a0sudo<\/code>. This group has the privilege of running the commands with sudo access.<\/p>\n

Modifying sudoers file<\/h4>\n

The other way is to put your user in the\u00a0sudoers<\/code>\u00a0file. If your server has multiple users with root privileges, then this approach is somewhat better because if someone messes with the\u00a0sudo<\/code>\u00a0group, you will be still able to run commands with root privileges to work on the server.<\/p>\n

First, run this command:<\/p>\n

visudo\r\n<\/code><\/pre>\n

This will open the\u00a0sudoers<\/code>\u00a0file. This file contains the definitions of groups and users who can run commands with root privileges.<\/p>\n

root    ALL=(ALL:ALL) ALL\r\n<\/code><\/pre>\n

After this line, write your user name and grant it full root privileges. Replace\u00a0username<\/code>\u00a0accordingly:<\/p>\n

username    ALL=(ALL:ALL) ALL\r\n<\/code><\/pre>\n

Save and close the file (Ctrl + O<\/strong>\u00a0and\u00a0Ctrl + X<\/strong>\u00a0in nano).<\/p>\n

Testing your new user<\/h4>\n

To login to your new user account without\u00a0logout<\/code>\u00a0and\u00a0login<\/code>, simply call:<\/p>\n

su username\r\n<\/code><\/pre>\n

Test sudo permissions using this command:<\/p>\n

sudo apt-get update\r\n<\/code><\/pre>\n

The shell will ask for your password. If sudo was configured properly, then your repositories should be updated. Otherwise, review the previous steps.<\/p>\n

Now, logout from the new user:<\/p>\n

exit\r\n<\/code><\/pre>\n

Sudo setup is complete.<\/p>\n

Securing SSH<\/h3>\n

The next part of this guide involves securing the ssh login to the server. First, change the root password:<\/p>\n

passwd root\r\n<\/code><\/pre>\n

Choose something hard to guess, but that you can remember.<\/p>\n

SSH key<\/h4>\n

SSH keys are a safer way to login. If you are not interested in SSH keys, skip to the next part of the tutorial.<\/p>\n

Use the following AKLWEB Host Doc to make an SSH key:\u00a0How Do I Generate SSH Keys?<\/strong><\/span><\/a><\/p>\n

After you get your\u00a0public key<\/strong>, login with your new user again.<\/p>\n

su username\r\n<\/code><\/pre>\n

Now make the\u00a0.ssh<\/code>\u00a0directory and the\u00a0authorized_keys<\/code>\u00a0file in the home directory of that user account.<\/p>\n

cd ~\r\nmkdir .ssh\r\nchmod 700 .ssh\r\ntouch .ssh\/authorized_keys\r\n<\/code><\/pre>\n

Add the public key that you generated from the other tutorial to the\u00a0authorized_keys<\/code>\u00a0file.<\/p>\n

 nano .ssh\/authorized_keys\r\n<\/code><\/pre>\n

Save the file, then change the permissions of that file.<\/p>\n

chmod 600 .ssh\/authorized_keys\r\n<\/code><\/pre>\n

Return to the root user.<\/p>\n

exit\r\n<\/code><\/pre>\n

SSH configuration<\/h4>\n

Now we will make the SSH daemon more secure. Let’s start with the config file:<\/p>\n

nano \/etc\/ssh\/sshd_config\r\n<\/code><\/pre>\n
Change SSH inbound port<\/h6>\n

This step will change the port used to access the server, it is entirely optional but recommended.<\/em><\/p>\n

Find the line with the\u00a0Port<\/code>\u00a0config, should look like this:<\/p>\n

Port 22\r\n<\/code><\/pre>\n

Now change this port to any port that you want. It must be greater than 1024.<\/p>\n

Port 4422\r\n<\/code><\/pre>\n
Disable root ssh login<\/h6>\n

This step will disable root login through SSH, it is entirely optional but\u00a0highly<\/strong>\u00a0recommended<\/em>.<\/p>\n

Find this line:<\/p>\n

PermitRootLogin yes\r\n<\/code><\/pre>\n

… and change it to:<\/p>\n

PermitRootLogin no\r\n<\/code><\/pre>\n

This will make the server more secure against\u00a0bots<\/strong>\u00a0that try brute force and\/or common passwords with user\u00a0root<\/code>\u00a0and port 22.<\/p>\n

Disable X11 forward<\/h6>\n

This step will disable X11 forwarding, don’t do this if you use some remote desktop program to access to your server.<\/em><\/p>\n

Find the X11 line:<\/p>\n

X11Forwarding yes\r\n<\/code><\/pre>\n

… and it change to:<\/p>\n

X11Forwarding no\r\n<\/code><\/pre>\n
Restart SSH daemon<\/h6>\n

Now that we made the changes to secure the SSH Login, restart the SSH service:<\/p>\n

service ssh restart\r\n<\/code><\/pre>\n

This will restart and reload the server settings.<\/p>\n

Testing changes<\/h6>\n

Without disconnecting your current ssh session, open a new terminal or PuTTY window and test another SSH login.<\/p>\n

ssh -p 4422 username@SERVER_IP_OR_DOMAIN\r\n<\/code><\/pre>\n

If everything checks out, we have successfully hardened the security of your server. Enjoy!<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[229,242,247],"manual_kb_tag":[460],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2922"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2922"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2922\/revisions"}],"predecessor-version":[{"id":2923,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2922\/revisions\/2923"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2922"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2922"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}