Windows Server in EC2 Intro

From csn
Jump to navigation Jump to search

Launch a Windows 2019 Base Server in the cloud. As Windows Server runs a GUI by default, it generally requires more resources than Linux. To make my experience a little more snappy, I chose a moderate instance and was happy to accept the small additional cost for this convenience. Choose as you see fit. You should also open ports for RDP, HTTP, FTP and HTTPS.

Connecting to Windows Server in EC2

Go to https://console.aws.amazon.com then EC2 and launch your Windows server instance, I chose the "Windows 2019 Base" Amazon Machine Image that was Free Tier Elligible. Then right-click on the instance and click Connect.

This will open a window with the DNS name and the username. To obtain a password you will need to upload your .pem key. You should store the resulting: DNS entry, username and password in a text file, in case you lose it while completing the lab but keep in mind that this may not be a great long term password management practice.

You can connect to your Windows server using any operating system.

You should experiment with the colour and resolution settings in the client connection to find something that works for your Internet Connection. If you have a fast Internet connection then you can choose higher quality settings.

Familiarity with the GUI

This lab should further your skills in Windows, and Powershell server scripts. By the end of this lab, you should note that Microsoft Powershell and Linux Bash are powerful and useful server scripting languages. There is no need to debate which is better as they are both now multi-platform and you can now use the scripting language of your choice in Windows or Linux.

Bash on Windows
Bash on Windows

Familiarise yourself with the server environment using the GUI:

  • What CPU is your machine running? (Is it a server or desktop-class processor?)
  • How much memory and disk space do you have?
  • Open a web browser and type where am i in the URL bar. Note that Windows Server can have a strict security policy. You may need to manually permit access to each website. You should see the location of the data centre displayed in the output.

Windows CLI Basics

Click on the start menu and search for powershell ISE and open it. Be sure to open the ISE version of Powershell, as this is the integrated environment that provides both an editor where you can write scripts and a command-line from which you can execute them.

Type the following commands and answer the questions. Hint: Regardless of the CLI environment that I am working in (Linux, Cisco, Windows), I tend to use the tab key to auto complete my commands. Make sure you give it a try.

What is your IPv4 IP address? Try:

ipconfig

What ports are open? Try:

netstat -an

Identify the RDP session to your windows server. What is the Global IP address of the machine you are RDP'ing from?

whoami

This command is the same as Linux but will return domain\username. If your computer isn't connected to a domain this command will return computer name\username.

dir

Try the linux equivalent

ls

This will create an empty file.

notepad emptyfile.txt

This will open a text file for editing. Add some text then save and exit. Retype:

dir

You should note emptyfile.txt. It should be greater than 0 bytes. Copy the file into Downloads.

copy emptyfile.txt Downloads\

Then go and check that the file has moved to the desired location.

cd Downloads

Remove the original file created.

cd ..
del emptyfile.txt

This time we are going to move the file back to the original location. Note that with the commands that we are going to use absolute paths:
You will need to adjust the path to reflect your username and home directory. (see "whoami")

move C:\Users\<Username>\Downloads\emptyfile.txt C:\Users\<Username>\

Starting and Ending Processes

List the programs that are running on your Windows system:

tasklist

What is this command and what is the equivalent in Linux? Start Notepad from the command line:

notepad

Re-run:

tasklist

Find the Notepad process. Kill this process from the command line. You can do this with the name or the Process ID (PID). The /f is for "force"

taskkill /f /im myprocess.exe

OR

taskkill /f /pid 1234

Running a Webserver on Windows (IIS)

Similar to Linux, Windows also provides a range of different services that Enterprise and Internet Servers would want to run. Most of the services that you would want to run are provided by windows and can simply be activated. To see the list of available services, click on Windows Start bar and type

Server Manager

Hit enter to open Server Manager then click

 Add roles and features

Then hit next to accept the defaults until you hit Server Roles. Under Server Roles, you want to enable Web Server (IIS). Hit next to enable this feature and install the Windows Web Server.

Test the installation locally. From your Windows Server machine Open your web browser, Internet Explorer, and browse to:

127.0.0.1

Hopefully, you will see the windows IIS default page. If you don't see the default page, ask your tutor and troubleshoot. You may find you need to prefix the address with http://127.0.0.1 as some Microsoft browsers will assume you are searching for information rather than visiting a site.

Test from the physical machine sitting in front of you. Go to Amazon EC2 and record the public IP address of your windows server machine.

Then, paste that IP address into your web browser and test the operation of your web browser.

On Linux, we can edit the index.html page in /var/www/index.html. In Windows, this file is stored at c:/inetpub/wwwroot/iisstart.htm

Edit this file with

notepad c:/inetpub/wwwroot/iisstart.htm

After you have done this, refresh your web page to see the changes that you have made.

Adding Users

On Windows server, you are currently the Administrator. Let's add three users, Alice, Bob and Mallory.

Click on the start menu and type:

add user

Then hit enter. Then click add someone else to this PC.

Under Actions on the right, click More Actions under Users, then new User. Independently add Alice, Bob and Mallory giving each user a strong password that you will remember.

Running a FTP Server on Windows IIS

To enable FTP under IIS, click on Windows Start bar and type

Server Manager

Hit enter to open Server Manager then click

 Add roles and features

Then hit next to accept the defaults until you hit Server Roles. Under Server Roles, you want to enable Web Server (IIS), as well as the FTP server. Make sure the FTP server is ticked then hit next to enable this feature and install the Windows FTP Server.

To setup the FTP server, go to:

Control Panel->Administrative Tools->Internet Information Services (IIS) Manager

Alternately, you can simply search for "IIS Manager" from the Start menu. Under Connections on the left, click on the hostname to open a new page. Once open, click on the view sites link on the right hand side of the page to add a new FTP site. Then click Add FTP Site and share a folder.

Lets enable this FTP server to be read by all users. To do this:

  • Don't require SSL
  • Use basic authentication
  • Under authorization, allow access to all users
  • Only check the read option

Check that your FTP server is working as expected by browsing* to:

ftp://127.0.0.1 (If your Windows user account doesn't have a password configured, go to Control Panel -> User Accounts and configure one)

Two questions:

  • Why do we need to enter ftp?
  • What does 127.0.0.1 do?

Try getting you lab partner to access your web page and your ftp site. Remember to check whether the firewall ports are open. What ports would we need to open for external HTTP and FTP access?

(* Windows 10 users, note that "Microsoft Edge" is optimised for mobile devices and Microsoft doesn't support FTP on this browser.)