Initial Setup

29/05/25

Basic Networking

Day 2, I now have my old laptop freshly set up with Debian on it. So the way my setup is now is I have my laptop connected to my router via ethernet and my main Ubuntu PC connected via Wi-Fi. In order to be able to network between my machines, the first thing I have to do is configure their respective network interfaces with a static IP so that I can easily identify them and SSH into my laptop from my main machine.

By default the Debian laptop is using ifupdown for network management. And so I learnt that network configuration takes place in the /etc/network/ directory, specifically the /etc/network/interfaces file.

When inspecting the configuration file, I learnt that by default the ethernet interface was using something called the DHCP protocol. What the DHCP protocol does is it obtains a LAN IP address automatically from the router. So my possible options were reserving a static IP on the router level or on the machine level. I logged in to my router's admin panel and saw that the pool of IPs that DHCP was using was from 192.168.1.10 to 192.168.1.254:

DHCP pool

I also had a look at the currently used IPs on the network by devices and they were all in the DHCP pool. So that meant that the free IPs were between 192.168.1.2 and 192.168.1.9 (192.168.1.1 being my router). I decided on 192.168.1.5 to be the static IP for my laptop's ethernet interface.

To configure the ethernet interface the way I wanted, I had to update the ethernet interface block in /etc/network/interfaces as so:

auto enp1s0 iface enp1s0 inet static address 192.168.1.5 netmask 255.255.255.0

Then I had to restart the interface with sudo ifdown enp1s0 && sudo ifup enp1s0 in order for the new config to take effect.

Next was the static IP on the Ubuntu machine. My Ubuntu machine was/is using Network Manager and so, I had to use nmcli to configure the Wi-Fi network interface with a static IP. I decided to use 192.168.1.6 and so I had to enter the following commands to configure it as such, first deleting the old connection config and adding a new one:

nmcli connection delete TALKTALKB42F10 nmcli connection add type wifi ifname wlp6s0 con-name static-wifi ssid "TALKTALKB42F10" nmcli connection modify static-wifi \ wifi-sec.key-mgmt wpa-psk wifi-sec.psk "12345678" ipv4.addresses 192.168.1.6/24 ipv4.gateway 192.168.1.1 ipv4.method manual

Then I ran the following to bring up the network interface: nmcli connection up static-wifi.

I tried pinging the laptop's IP from my PC and I got successful output:

jiggy@ubuntu:~$ ping 192.168.10.5 PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data. 64 bytes from 192.168.1.5: icmp_seq=1 ttl=64 time=89.7ms 64 bytes from 192.168.1.5: icmp_seq=2 ttl=64 time=9.75ms 64 bytes from 192.168.1.5: icmp_seq=3 ttl=64 time=31.3ms 64 bytes from 192.168.1.5: icmp_seq=4 ttl=64 time=54.3ms ^C --- 192.168.1.5 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3005ms rtt min/avg/max/mdev = 9.754/46.258/89.691/29.607 ms

The same also happened when I tried in the reverse direction, so now I could successfully network between my machines.

SSH

Since I could successfully network between machines I tried SSH'ing into the laptop with password authentication, and that also worked which was huge.

But naturally I want to use public key authentication because it's better than the default password authentication. Setting up and working with SSH keys is something that I've done multiple times but I always forget the ins and outs so I had to use GPT as a guide. But now I have the process documented below so I won't forget.

Step 1 is generating a key pair with ssh-keygen. I added a passphrase to the private key when prompted so only I can use the key which is standard. I named the key debian-box after the target machine.

Step 2 is copying the SSH public key to the server with ssh-copy-id. I used ssh-copy-id -i ~/.ssh/debian-box.pub [email protected] in my case. That prompted me for the user's password which I entered and then it successfully completed.

I tried SSH'ing and now it was using key authentication which was a good sign. Key authentication is set up however, every time I SSH I am prompted for the passphrase which is annoying. So I ran ssh-add ~/.ssh/debian-box which adds the passphrase to ssh-agent.

Some notes on ssh-agent since I learnt about this for the first time:

I also added the following block to ~/.ssh/config to make SSH'ing easier:

Host debian-box HostName 192.168.1.5 User jiggy IdentityFile ~/.ssh/debian-box

However when I tried SSH'ing with the new alias using ssh debian-box I got this message: Bad owner or permissions on /home/jiggy/.ssh/config. That apparently means that the config file has too many permissions making it a security risk. That makes sense because I created the file with nano so the permissions weren't set correctly by default. I had to change the permissions from 644 to 600 which is apparently the ideal for the config file: chmod 600 ~/.ssh/config.

For future reference:

So after all that was sorted, I tried ssh debian-box again and it worked with my passphrase / private key added to ssh-agent. Now I have easy SSH access to my Debian laptop which was the original goal.

I also disabled password authentication on the Debian machine by adding the following line to /etc/ssh/sshd_config: PasswordAuthentication no. And then restarting the SSH service: sudo systemctl restart ssh.

Basic Power Control

With SSH access I realised the only issue was that when closing the laptop lid, the machine went into suspense which wasn't ideal because then networking wouldn't be available. If I didn't want it to go into suspense I learnt that I had to configure the login daemon in /etc/systemd/logind.conf.

I had to add the following lines so that the laptop wouldn't suspend when closing the lid:

HandleLidSwitch=ignore HandleLidSwitchDocker=ignore

Then I restarted the login daemon with sudo systemctl restart systemd-logind and now everything was good.

I also learnt that sudo poweroff powers off the machine and you can also run that command over SSH safely which is neat.