Preliminary Configuration process of Linux server

Source: Internet
Author: User
When developing a website, you often need to configure your own Linux server. This document records the initial process for configuring the Linux server, that is, what to do next after the system is installed. This is my own summary and memo. if you have any omissions, please add them. Linux server

When developing a website, you often need to configure your own Linux server.

This document records the initial process for configuring the Linux server, that is, what to do next after the system is installed. This is my own summary and memo. if you have any omissions, please add them.

The following operations are applicable to Debian and Ubuntu systems. Other Linux systems are similar, that is, some commands are slightly different.

Step 1: log on as the root user

First, use the root user to log on to the remote host (assuming the IP address is 128.199.209.242 ).

 
  1. ssh root@128.199.209.242 

At this time, the command line prompts a warning, indicating that this is a new address and there is a security risk. Type yes to accept. Then, you can successfully log on to the remote host.

Next, modify the password of the root user.

 
  1. passwd 

Step 2: Create a user

First, add a user group (this is assumed to be the admin user group ).

 
  1. addgroup admin 

Then, add a new user (assumed as bill ).

 
  1. useradd -d /home/bill -s /bin/bash -m bill  

In the preceding command, the parameter d specifies the user's home directory, and the parameter s specifies the user's shell. the parameter m indicates that if the directory does not exist, the directory is created.

Next, set the password for the new user.

 
  1. passwd bill  

Add a new user (bill) to the user group (admin ).

 
  1. usermod -a -G admin bill  

Next, set sudo permissions for the new user.

 
  1. visudo  

The cmddo command will open the sudo setting file/etc/sudoers and find the following line.

 
  1. root    ALL=(ALL:ALL) ALL 

Add another row under this row.

 
  1. root    ALL=(ALL:ALL) ALL 
  2. bill    ALL=(ALL) NOPASSWD: ALL 

The above NOPASSWD indicates that you do not need to enter a password when switching to sudo. it is easier for me to do so. For security reasons, you can also force a password.

 
  1. root    ALL=(ALL:ALL) ALL 
  2. bill    ALL=(ALL:ALL) ALL 

Then, log out of the root user and log in as a new user. check whether everything is normal until this step ends.

 
  1. exit 
  2. ssh bill@128.199.209.242 

Step 3: Set SSH

First, make sure that the local machine has an SSH public key (usually a file ~ /. Ssh/id_rsa.pub). If not, use the ssh-keygen command to generate one (refer to the SSH tutorial I wrote ).

Open another shell window on the local machine to copy the local public key to the authorized_keys file on the server.

 
  1. Cat ~ /. Ssh/id_rsa.pub | ssh bill@128.199.209.242 'mkdir-p. ssh & cat-> ~ /. Ssh/authorized_keys'
  2. # Or on the server side, run the following command
  3. Echo "ssh-rsa [your public key]"> ~ /. Ssh/authorized_keys

Then, go to the server and edit the SSH configuration file/etc/ssh/sshd_config.

 
  1. sudo cp /etc/ssh/sshd_config ~ 
  2. sudo nano /etc/ssh/sshd_config 

In the configuration file, change the default SSH port 22 to any integer from 1025 to 65536 (this is assumed to be 25000 ).

 
  1. Port 25000 

Then, check whether the settings are set as follows to ensure that the # above is removed.

 
  1. Protocol 2 
  2. PermitRootLogin no 
  3. PermitEmptyPasswords no 
  4. PasswordAuthentication no 
  5. RSAAuthentication yes 
  6. PubkeyAuthentication yes 
  7. AuthorizedKeysFile .ssh/authorized_keys 
  8. UseDNS no 

In the preceding section, root user logon is disabled and password logon is disabled.

Next, at the end of the configuration file, specify the user that is allowed to log on.

 
  1. AllowUsers bill 

Save and exit file editing.

Then, change the permissions of the authorized_keys file.

 
  1. sudo chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh/ 

Then, restart SSHD.

 
  1. Sudo service ssh restart
  2. # Or
  3. Sudo/etc/init. d/ssh restart

The following steps are optional. On the local machine ~ /. Create the config file in the ssh folder. the content is as follows.

 
  1. Host s1 
  2. HostName 128.199.209.242 
  3. User bill 
  4. Port 25000 

Finally, open a shell window on the local machine to test whether SSH can log on smoothly.

 
  1. ssh s1 

Step 4: configure the runtime environment

First, check the region settings of the server.

 
  1. locale 

If the result is not a en_US.UTF-8, we recommend setting it to it.

 
  1. sudo locale-gen en_US en_US.UTF-8 en_CA.UTF-8 
  2. sudo dpkg-reconfigure locales 

Then, update the software.

 
  1. sudo apt-get update 
  2. sudo apt-get upgrade 

Finally, make some security settings as needed, such as building a firewall, closing ports other than HTTP, HTTPs, and SSH, and installing Fail2Ban, for details, refer to Securing a Linux Server.

Link: http://www.ruanyifeng.com/blog/2014/03/server_setup.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.