I had an RPI3B running a web server, samba server, rss server, with raspbian and software fully updated, with root file system on an SSD. I just switched the SD and SSD over to an RPI4, rebooted, and everything "just worked".
Now, there may be corner cases which rely on the hardware in some way, or speed of operation, etc, but for "straightforward" use cases, a simple switch of this kind appears to work just fine for raspbian. Ubuntu should be similar, but may differ.