Skip to content

Instantly share code, notes, and snippets.

@mnadjit
Last active May 13, 2022 14:16
Show Gist options
  • Save mnadjit/41efcd3e440c9d3a08c498860f392341 to your computer and use it in GitHub Desktop.
Save mnadjit/41efcd3e440c9d3a08c498860f392341 to your computer and use it in GitHub Desktop.
A collection of commands to set up an ubuntu server

Hardware

`sudo lshw`
`sudo lshw -businfo`

CPU

  • CPU physcial info: sudo lshw -businfo | grep cpu
  • CPU details: cat /proc/cpuinfo
  • CPU architecture:lscpu | grep -i arch
  • CPU detailed info: cpuid

Memory

  • RAM physical info: sudo lshw -businfo | grep memory
  • Total and available memory: free -h -t
  • Get total memory: grep -i memtotal /proc/meminfo

Disk

  • Disk size and model: sudo lshw -businfo | grep disk
  • Disk space and its partitions: lsblk -p
  • Disk space info: df -h
  • Disk partitions size and fs human-readable: parted -l
  • Partition UUIDs: blkid
  • Partitioning the disks: cfdisk

Network

  • Network physical info: sudo lshw -businfo | grep network

PCI bus info:

lspci -v

Devices on USB bus:

sudo lsusb -v

Kernel modules that are loaded and running:

lsmod
lsmod | grep ath

Start module:

sudo modprobe <module>

Stop module:

sudo modprobe -r <module>

Check blocking hardware or software on RF devices:

rfkill list

Network

sudo lshw -C network
lspci -v | grep Ethernet
sudo iwconfig
ip addr

Enable an interface if down:

ifconfig <interface> up
# other options ifup/ifdown and nmcli (if installed)

Find all wireless networks around:

sudo iwlist <interface> scan

Set up WPA Wireless:

# set SSID and passphrase:
	wpa_passphrase <your-ESSID> <your-passphrase> | sudo tee /etc/wpa_supplicant/wpa_supplicant.conf
# Remove plain text password from wpa_supplicant.conf file:
	sudo sed -i '/#psk/d' /etc/wpa_supplicant/wpa_supplicant.conf
# Run wpa_supplicant in the background:
	sudo wpa_supplicant -B -c /etc/wpa_supplicant/wpa_supplicant.conf -i <interface>
# Check if connected:
	iwconfig
	# look for value next to Access Point

Enable DHCP client on an interface:

sudo dhclient <interface>

Enable WiFi at start-up:

sudo cp /lib/systemd/system/wpa_supplicant.service /etc/systemd/system/wpa_supplicant.service
# Replace line starting with ExecStart with the following:
	ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant.conf -i <interface>
# Add the following right after to restart on failure
	Restart=always
# comment out the following 
	Alias=dbus-fi.w1.wpa_supplicant1.service
# enable wpa_supplicant service to run at boot
	sudo systemctl enable wpa_supplicant.service

Enable DHCP client at start-up sudo nano /etc/systemd/system/dhclient.service # with the following content:

[Unit]
Description= DHCP Client
Before=network.target

[Service]
Type=forking
ExecStart=/sbin/dhclient <interface> -v
ExecStop=/sbin/dhclient <interface> -r
Restart=always

[Install] 
WantedBy=multi-user.target
# Enable dhclient service
	sudo systemctl enable dhclient.service

Static IP:

sudo nano /etc/dhcp/dhclient.conf
# Add the following: 
	interface "<interface>" {
 send dhcp-requested-address <ip-address>;

}

Restart Network Service (if ever needed):

systemctl restart network
# or
systemctl restart network.service

Memory

Free Memory:

free -m

SSH

Enable and start SSH:

systemctl enable ssh
systemctl start ssh

Re-create SSH keys in ed25519 & ecdsa formats if SSH fails

ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519

ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa

Firewall

Enable firewall (TBC!)

# ufw enable
# ufw allow ssh

Manage Users

add new user and create home directory

# -m adds home dir / -s fixes the prompt / 
	sudo useradd -m -s /bin/bash <username>
# give the user root permissions
	sudo usermod -aG sudo <username>
	# check if user is root - the following should prompt "root"

sudo whoami

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment