joseph zhong

building a small pc [6/N]

now to enable SSH

This was actually really easy; just log into your router (figure out what your private IP address and admin password, written on the router) and just set up Port-Forwarding for TCP/22 and fwd to your system’s private IP

  1. Get Private IP Address on Server

For example:

$ ifconfig | grep inet
24:        inet 127.0.0.1  netmask 255.0.0.0
25:        inet6 ::1  prefixlen 128  scopeid 0x10<host>
33:        inet 192.168.W.XYZ  netmask 255.255.255.0  broadcast 192.168.1.666
34:        inet6 aa11::b1c2:1a2b:1122:1bf1  prefixlen 64  scopeid 0x20<link>
  1. Setup your Port Forwarding

Find your router IP and admin password and set up the SSH port-forward

I also use Eternal Terminal for my development which requires a second port: see my previous blog on that setup here: http://blog.josephzho.ng/2021/04/02/macos-setup/

For example:

Application Original Port Protocol Fwd to Addr
ssh 22 TCP 192.168.W.XYZ
et XYXX TCP 192.168.W.XYZ
  1. Save router settings, and test SSH!

On server:

$ sudo apt-get upgrade
$ sudo apt-get install openssh-client
$ sudo apt-get install openssh-server
$ ps -A | grep sshd
[number] ?	00:00:00 sshd

On Laptop

ssh [username]@[public ip address]
  1. Once this is working, now we can customize some security settings since this is our personal home computer after all!

On Laptop create SSH keys and copy them to the server – important do this first! Don’t edit the default sshd_config settings without this otherwise you’ll be debugging stuff!

ssh-keygen -t ed25519 -C joseph.zhong@hotmail.com
ssh-copy-id josephz@[public ip address]

On your server this will involve editing /etc/ssh/sshd_config

Here there’s a bunch of settings: I prefer to disable password (SSH only!), limit the attempts. Maybe there’s more I’ll change in the future.

sudo vim /etc/ssh/sshd_config
...
systemctl restart ssh.service

Now finally verify that SSH-with-keys works, on laptop

ssh [username]@[public ip]
# verify no password is prompted!
  1. Whenever we shutdown / reboot our server, it’s possible our private IP address will change, let’s change that

On Server

$ nmcli dev show  | grep ip
8:IP4.ADDRESS[1]:                         192.168.W.XYZ/AB
9:IP4.GATEWAY:                            192.168.W.X
10:IP4.ROUTE[1]:                           dst = 192.168.X.Y/AB, nh = 0.0.0.0, mt = 600
11:IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 192.168.X.Y, mt = 600
12:IP4.DNS[1]:                             192.168.X.Y
13:IP4.DOMAIN[1]:                          myfiosgateway.com
...

On Server, go to Settings > WiFi > IPv4 and switch to IPv4 Method > Manual

Now we need to set Address/Netmask/Gateway as accordingly from above

Address: 192.168.W.XYZ
Netmask: AB
Gateway: 192.168.W.X

EDIT: I was finally getting really really fed up with my Terminal not following the keyboard shortcuts, so I instead found WinTile which allows you to drag windows to the corner/sides/top to quarter/half/full-size a window as-done in Windows. One additional niceity is that it has an animation preview just like in Windows but you can shorten the preview-delay down to 25ms making it super snappy!

Had to hack it a little bit to be supported out of box since it hasn’t been shipped yet for GNOME-42 but seems to work out-of-box for my needs.

Once you download an extension (e.g. from https://github.com/Fmstrat/wintile or the Extensions site), unzip the files to

$ unzip /path/to/extension.zip -d [output-dir]
$ cat [output-dir]/metadata.json | grep uuid
17:  "uuid": "wintile@nowsci.com",
$ mv [output-dir] "wintile@nowsci.com"/
$ mv "wintile@nowsci.com"/ ~/.local/share/gnome-shell/extensions/

# Restart Gnome-Shell with `Alt+F2 > 'r' > 'enter'`
$ gnome-extensions enable wintile@nowsci.com

At this point you’ll be able to enable the new extension in the Extensions app!