Friday, 9 May 2025

How to Set Up SSH in Ubuntu VM

How to Set Up SSH in Ubuntu VM

SSH (Secure Shell) is a powerful tool that allows you to remotely access and manage your Ubuntu system. This guide explains how to install and configure SSH, and also how to fix common connection issues—especially when accessing a guest VM (like Ubuntu in VirtualBox) from a host machine.

Step 1: Install SSH Server on Ubuntu

sudo apt update
sudo apt install openssh-server

Check if it's running:

sudo systemctl status ssh

If it's not active, start it:

sudo systemctl start ssh

Enable it at boot:

sudo systemctl enable ssh

Step 2: Find Ubuntu’s IP Address

hostname -I

or

ip a

Step 3: Connect via SSH

From another machine on the same network:

ssh username@your_ubuntu_ip

Step 4: Configure SSH Settings (Optional)

Edit the config file:

sudo nano /etc/ssh/sshd_config

Then restart SSH:

sudo systemctl restart ssh

Step 5: Set Up SSH Key Authentication (Optional)

On the client machine:

ssh-keygen
ssh-copy-id username@your_ubuntu_ip

Troubleshooting: “Connection Refused” in VirtualBox

If you're trying to SSH from host to guest and get “connection refused,” check the following:

1. Is SSH Running?

sudo systemctl status ssh

2. Check VirtualBox Network Settings

  • Bridged Adapter: Recommended for easiest access from host to guest.
  • NAT: Needs port forwarding to work with SSH.

3. Port Forwarding for NAT

Go to Settings → Network → Advanced → Port Forwarding and add:

FieldValue
ProtocolTCP
Host IP127.0.0.1
Host Port2222
Guest IP(leave blank or use 10.0.2.15)
Guest Port22

Then connect using:

ssh username@127.0.0.1 -p 2222

4. Firewall Blocking SSH

sudo ufw status

If active:

sudo ufw allow ssh
sudo ufw reload

Quick Checklist

StepCommand/Setting
Install SSHsudo apt install openssh-server
Start SSHsudo systemctl start ssh
Network TypeUse Bridged or set up NAT Port Forwarding
Firewallsudo ufw allow ssh
Connectssh user@ip or ssh user@127.0.0.1 -p port

Conclusion

Setting up SSH in Ubuntu is straightforward, but getting it to work in a virtual environment requires special attention to networking. Use bridged mode for simplicity, or configure port forwarding in NAT mode. Ensure your firewall and SSH service are both active, and you’ll have a smooth remote access setup in no time.

Uncommon but Useful Linux Commands with Examples

Uncommon but Useful Linux Commands with Examples

Linux is a powerful operating system with thousands of commands, many of which are rarely discussed but extremely useful. Here are 10 lesser-known commands every Linux user should know.

1. tldr – Simplified Command Help

Provides simplified and community-driven man pages.

tldr tar

Example usage summary of tar with common examples.

2. ncdu – NCurses Disk Usage

Interactive way to view and manage disk usage.

ncdu /home

3. bat – A Better Cat

A modern replacement for cat with syntax highlighting and line numbers.

bat script.sh

4. fzf – Fuzzy File Finder

Quickly find files and directories using fuzzy search.

fzf

5. watch – Re-run Commands at Intervals

Runs a command repeatedly and shows the output live.

watch -n 5 df -h

Refreshes disk usage info every 5 seconds.

6. tree – Visual Directory Tree

Displays directory structure in a tree-like format.

tree /var/log

7. xxd – Make a Hex Dump

Creates a hex dump of a file, useful for debugging binary files.

xxd file.bin

8. nmap – Network Scanner

Scan open ports and discover network hosts.

nmap 192.168.1.0/24

9. column – Format Output into Columns

Aligns output into neat columns for readability.

cat data.txt | column -t

10. shuf – Shuffle Lines of a File

Randomizes lines in a file or output.

shuf names.txt

These uncommon commands can significantly improve your Linux workflow and help you discover new capabilities in your system. Try them out and elevate your terminal experience!

Useful Linux Commands with Examples

Useful Linux Commands with Examples

Whether you're a beginner or a seasoned Linux user, mastering a few essential commands can significantly boost your productivity. Here's a list of the top 10 most useful Linux commands with examples.

1. ls – List Directory Contents

Lists files and directories in the current directory.

ls -l

Displays detailed information about each file.

2. cd – Change Directory

Changes the current working directory.

cd /home/username/Documents

3. pwd – Print Working Directory

Shows the full path of your current directory.

pwd

4. mkdir – Make Directory

Creates a new directory.

mkdir new_folder

5. rm – Remove Files or Directories

Deletes files or directories.

rm file.txt

Use rm -r for recursive deletion of folders.

6. cp – Copy Files and Directories

Copies files or directories from one location to another.

cp source.txt destination.txt

7. mv – Move or Rename Files

Moves or renames a file or directory.

mv oldname.txt newname.txt

8. cat – View File Contents

Displays the contents of a file.

cat file.txt

9. grep – Search Inside Files

Searches for patterns within files.

grep "hello" file.txt

10. top – Monitor System Processes

Displays real-time information about system processes.

top

Mastering these commands lays the foundation for efficient Linux usage. Stay tuned for more tips and tricks in upcoming posts!

Web Scraping with Beautiful Soup in Python 3

Web Scraping with Beautiful Soup in Python 3

Beautiful Soup is a powerful Python library used for parsing HTML and XML documents. It creates parse trees that are helpful for extracting data easily. This tutorial demonstrates how to use Beautiful Soup to scrape a website.

Installing Beautiful Soup

pip install beautifulsoup4 requests

Basic Example

The following Python code fetches and parses the content of a web page:

import requests
from bs4 import BeautifulSoup

# Send a request to the website
url = 'https://example.com'
response = requests.get(url)

# Parse the content
soup = BeautifulSoup(response.content, 'html.parser')

# Print the page title
print(soup.title.text)

Extracting Links

You can easily extract all the links on a web page:

for link in soup.find_all('a'):
    href = link.get('href')
    text = link.text.strip()
    print(f'Text: {text}, URL: {href}')

Finding Elements by Class or ID

# Find element by class name
item = soup.find('div', class_='item-class')
print(item.text)

# Find element by ID
header = soup.find(id='main-header')
print(header.text)

Conclusion

Beautiful Soup is an excellent tool for web scraping when used responsibly. Always check the website's terms of service and robots.txt before scraping.