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.
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:
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.
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.
Command: whoami
Command: who
Command: df –h
Command: ps aux
5. Memory usage:
Command: free –h
6. Manage Files and Folders:
Command: ls –l
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
7. Update server
Command: sudo apt update && sudo apt upgrade –y
Command: sudo apt autoremove -y && sudo apt autoclean
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).
Change SSH port
Command: sudo nano /etc/ssh/sshd_config
Find line Port 22.
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
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.
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
Find #Port 22.
Now, uncomment the line and change the port to 2222. Save and close the file.
Command: New-NetFirewallRule -Name sshd-2222 -DisplayName “OpenSSH Server (Port 2222)” -Enabled True -Direction Inbound -Protocol TCP -LocalPort 2222 -Action Allow
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).
Command: netstat -an | findstr 2222
You will see the message as shown in the screen below.
Have additional questions? Search below: