首页 > 系统相关 >1_Setting Up an Ubuntu 20.04 server for deployment

1_Setting Up an Ubuntu 20.04 server for deployment

时间:2023-06-06 19:22:14浏览次数:65  
标签:Up server will user Ubuntu following Copy root

 

原文:https://www.codewithharry.com/blogpost/setup-ubuntu-20-04-server/

 

 

Setting Up an Ubuntu 20.04 server for deployment

When you first create a server from any provider like Linode, DigitalOcean, etc., you will have to secure it by executing several commands. This post will explain what those commands are and why you need to run all those commands to start using your server securely.

I will break down the procedure we will perform into 5 simple steps:

  1. Creating a VPS
  2. Initial Login 
  3. Creating a non-root user
  4. Firewall setup

Let's get started

 

 

 

Creating a VPS

For creating a VPS, I will choose DigitalOcean. I have been DigitalOcean for quite a while now, and it never disappointed me. There are other service providers like Linode, Vultr, etc.

Once you create an account on DigitalOcean and log in, DigitalOcean will present you with this screen. Click on create and then on droplets:

DigitalOcean will present you with the following screen, where you can choose the droplet, Operating system, and plan size. I will choose the options as marked in red below:

Choose a region. Ideally, this has to be the region closest to your users. This is the physical location where the server will be located:

 

 

 

Finally, choose a password and click create droplet:

You will see processing like this

and finally, we will get a public IP address

We will use this public IP address to login into our server

 

 

 

Initial Login

The very first step to start using a server is to log in to it. A web server is just like a computer on the web. We cannot connect a physical keyboard and mouse to it. So how do we use it?  We will use an SSH Client to get access to the server's terminal (this remote computer), and once we have access to the terminal, we can start executing commands on this server. 

To log in to our server, we need to know its public IP address, just like you need to know the address of a place before visiting it. 

Execute the following command on the PowerShell or terminal

ssh root@your_server_ip

I will type this:

ssh root@165.232.177.116

Enter the password provided by your service provider. We have created a password in DigitalOcean, which we will enter here. Once you enter the password when prompted, you will be logged in as root.

The root user is a user having the highest privileges on the server. This means that a root user can do anything and everything on the server. This is why it is strongly discouraged to use a root account as it might accidentally delete files/uninstall programs/install programs etc. Hence we will create a user who will have restricted permissions on the server for day-to-day use.

 

 

 

Creating a non-root user

We will now create a non-root user account that will have restricted access to the machine. This is ideal if you want to have people working for you on the server without doing everything on the server.

Execute the following command:

adduser harry

You will be asked to enter some information and a password. Choose a strong password to avoid getting hacked!

We have successfully created an account with basic access. We want this user to be able to elevate to root access when required. This will be useful when you want to use your server and sometimes do something which requires root access.

This will save you the time to log out and log back in as the root user.

Execute the following command on the server:

usermod -aG sudo harry

 

 

 

Firewall setup

Our server is public, and we want to protect it from external unwanted connections. We want only selected services exposed to the public on our server.

We will set up the UFW firewall on our Ubuntu 20.04 server and allow OpenSSH, which allows us to connect to our server.
Execute the following command to allow OpenSSH:

ufw allow OpenSSH

Enable the firewall by executing the following command:

ufw enable

The firewall will now block all the connections except SSH

You have successfully created a new user. Try to log in through this user in a new terminal tab and verify everything works before logging out from the current session.

 

 

 

You can type the following command to elevate to the root access as and when required.

sudo su

To go back to the existing user, execute the following command:

exit

I hope this guide was helpful. Happy Coding!

 

 

 

标签:Up,server,will,user,Ubuntu,following,Copy,root
From: https://www.cnblogs.com/hechunfeng/p/17461485.html

相关文章

  • vSphere ESXi6.5创建Windows Server 2022虚拟机
    头一次操作,也踩了不少坑,故记录下一开始心里也没底,想着6.5的版本能支持2022嘛,新建的选项里最高也就2016,抱着试试看的心态装了下,没想到成了~ 1.下载iso镜像推荐渠道:MSDN:https://msdn.itellyou.cn/微软官网:https://www.microsoft.com/zh-cn/software-download/msdn老网站不......
  • Supermarket 3种解法保证看懂
    ​Description给定N个商品每个商品有利润p_i和过期时间d_i每天只能卖一个商品,过期商品不能再卖,求如何安排每天卖的商品,可以使收益最大。1≤N,p_i,d_i≤10^4。FormatInput测试做到文件底结束对于每组数据,先给出数字N接下来N行,每行两个数字代表pi与diOutput如题Sam......
  • mysql数据库的锁-select for update
    乐观锁与悲观锁乐观锁和悲观锁只是两个加锁的思路,其实现方式多种多样。以下举几个在mysql数据库中的例子。  对于一次的数据修改,我们可以大概将其分为三步:获取数据修改数据提交修改乐观锁假设A、B两个角色对数据进行修改:乐观锁对数据保持一个乐观态度(大概率......
  • ubuntu如何卸载软件
     一、ubuntu卸载软件要卸载Ubuntu系统中的软件,可以通过软件中心或终端命令行实现。可以在Ubuntu的应用程序菜单中找到“Ubuntu软件中心”,搜索需要卸载的软件,然后点击卸载按钮即可。使用终端命令行卸载软件时需要打开终端,输入以下命令:sudoapt-getremove软件名其中,“软件......
  • eclipse中gitee拉取项目:cannot open git-upload-pack
    检查本地是否有设置代理,关掉代理试试:......
  • Linux 的 nohup 命令的用法
    nohup/root/test.php&1、使用nohup让程序在远程主机后台运行http://www.williamlong.info/archives/482.html......
  • Establishing SSL connection without server's identity verification is not recomm
    WARN:EstablishingSSLconnectionwithoutserver’sidentityverificationisnotrecommended.AccordingtoMySQL5.5.45+,5.6.26+and5.7.6+requirementsSSLconnectionmustbeestablishedbydefaultifexplicitoptionisn’tset.Forcompliancewithexisti......
  • Postgresql,MySQL, SQL Server 的多表连接(join)update 操作
    数据库更新时经常会join其他表做判断更新,PostgreSQL的写法与其他关系型数据库更有不同,下面以SQLServer,MySQL,PostgreSQL的数据库做对比和展示。先造数据源。createtableA(idint,cityvarchar(20));createtableB(idint,namevarchar(20));insertintoAvalues(1......
  • Elasticsearch专题精讲—— REST APIs —— Document APIs —— Update By Query API
    RESTAPIs——DocumentAPIs—— UpdateByQueryAPIhttps://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-update-by-query.html#docs-update-by-queryUpdatesdocumentsthatmatchthespecifiedquery.Ifnoqueryisspecified,performsanupdateo......
  • Elasticsearch专题精讲—— REST APIs —— Document APIs —— Update API
    RESTAPIs——DocumentAPIs——UpdateAPIhttps://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-update.htmlUpdatesadocumentusingthespecifiedscript.使用指定的脚本更新文档。1、Request(请求)https://www......