How to Use Command Line Tools with Kamatera Servers

Leveraging command-line tools will help you gain more control and flexibility over your servers, making it easier to integrate Kamatera services into larger automation frameworks. This is mainly used by DevOps, system administrators, and anyone who wants to use cloud resources programmatically. By using command-line tools, you can:

 

In this article, we will go through all the steps to use SSH for Linux server management and Windows.

 

1. SSH for Linux

SSH (Secure Shell) provides a secure way to remotely access and manage Linux servers.

First, install an SSH Client:

On Linux/macOS: SSH is pre-installed, so you can directly use the terminal.

On Linux:

  1. Login with username and password in your Ubuntu terminal and run the commands below.

Ubuntu terminal screenshot

 

2. Otherwise, connect to the server:

 

Using Password

Open the terminal and type the below command

Command: ssh root@<server_ip>

Note: Replace server_ip with your actual Server IP Address.

 

When asked, type the password that you got from Kamatera and press Enter.

Ubuntu terminal screenshot

 

Using SSH Key

If Kamatera gave you a special key file, then type the below command

Command: ssh -i /path/to/key-file root@<server_ip>

Note: Replace server_ip with your actual Server IP Address.

 

    1. After connecting, you can use these simple commands in Ubuntu terminal.


Command: whoami

 

Ubuntu terminal screenshot

 

Command: who

Ubuntu terminal screenshot

Command: df –h

Ubuntu terminal screenshot

 

Command: ps aux

 

Ubuntu terminal screenshot

 

5. Memory usage:

 

Command: free –h

 

Ubuntu terminal screenshot

 

6. Manage Files and Folders:

Command: ls –l

 

Ubuntu terminal screenshot

 

Command: touch /path/to/directory/myfile.txt

Command: rm /path/to/file/myfile.txt

Command: mkdir /path/to/directory/my-folder

Command: rm -r /path/to/folder/my-folder

Command: cd /path/to/directory

Ubuntu terminal screenshot

 

7. Update server

Command: sudo apt update && sudo apt upgrade –y

 

Ubuntu terminal screenshot

 

Command: sudo apt autoremove -y && sudo apt autoclean

 

Ubuntu terminal screenshot

 

Install software

Command: sudo apt install <software-name>

Note: For demo purposes, in place of software-name, Flameshot is entered (which is an open-source tool to take screenshots). 

 

Ubuntu terminal screenshot

 

Change SSH port

Command: sudo nano /etc/ssh/sshd_config

 

 

Find line Port 22.

 

Ubuntu terminal screenshot

 

Modify the line to Port 2222.

 

 

Command: sudo systemctl restart ssh

 

 

Setup Firewall

Command: sudo ufw enable

 

 

Command: sudo ufw allow 2222/tcp

 

 

Command: sudo ufw status

 

2. SSH for Windows:

  1. In the start menu, type Windows PowerShell and select Run as Administrator.
  2. After connecting, you can use these simple commands.

Check Server status

 

Command: whoami

 

Command: query user

 

Command: Get-PSDrive

 

 

 

Command: Get-Process

 

 

 

Command: Get-WmiObject Win32_OperatingSystem | Select-Object @{Name=”TotalPhysicalMemory(GB)”;Expression={[math]::round($_.TotalVisibleMemorySize/1MB,2)}}, @{Name=”FreePhysicalMemory(GB)”;Expression={[math]::round($_.FreePhysicalMemory/1MB,2)}}

 

 

3. Manage Files and Folders:

Command: Get-ChildItem

 

 

Command: New-Item -Path “C:\path\to\directory\myfile.txt” -ItemType “File”

 

 

Command: Remove-Item “C:\path\to\file\my-file.txt”

 

 

Command: New-Item -Path “C:\path\to\directory” -Name “my-folder” -ItemType “Directory”

 

 

Command: Remove-Item “C:\path\to\folder\my-folder” -Recurse

 

 

Command: Set-Location “C:\path\to\directory”

 

 

4. Update Server:

Command: Install-Module -Name PSWindowsUpdate -Force -Scope CurrentUser

 

 

Command: Get-WindowsUpdate

 

Command: Install-WindowsUpdate -AcceptAll –AutoReboot

 

5. Install software

 

Command: Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString(‘https://community.chocolatey.org/install.ps1’))

 

Command: choco install <software-name>

6. Secure your Server

 

Command: Get-WindowsCapability -Online | Where-Object Name -like ‘OpenSSH*’

 

Command: Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Command: Get-WindowsCapability -Online | Where-Object Name -like ‘OpenSSH*’

 

 

Command: Start-Service sshd

Set-Service -Name sshd -StartupType Automatic

 

To know the status of OpenSSH Service, run the below command.

Command: Get-Service -Name sshd

 

 

Command: New-NetFirewallRule -Name sshd -DisplayName “OpenSSH Server (SSH)” -Enabled True -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow

Command: ssh localhost

If successful, you will see a login prompt. Enter your credentials, then you will see a new screen.

 

Now, you are in shell.

 

Screenshots of using command-line tools

 

7. Setting up a firewall

Windows does not use SSH by default for remote administration. However, if you’re using OpenSSH Server on Windows, you can change the SSH port by modifying the SSH Server configuration file and update your firewall settings.

Command: C:\ProgramData\ssh\sshd_config

Screenshots of using command-line tools

 

Find #Port 22.

Screenshots of using command-line tools

 

Now, uncomment the line and change the port to 2222. Save and close the file.

 

Screenshots of using command-line tools

 

Command: New-NetFirewallRule -Name sshd-2222 -DisplayName “OpenSSH Server (Port 2222)” -Enabled True -Direction Inbound -Protocol TCP -LocalPort 2222 -Action Allow

 

Screenshots of using command-line tools

 

Command: Restart-Service sshd

Verify the service is running or not.

Command: Get-Service sshd

You will see the server is running.

Connect to your SSH server using new port.

Command: ssh username@localhost -p 2222 (Replace username with your Windows Username).

 

Screenshots of using command-line tools

 

Command: netstat -an | findstr 2222

You will see the message as shown in the screen below.

 

Screenshots of using command-line tools

Have additional questions? Search below: