As anyone who has upgraded to Ubuntu 22+ will know, they have deprecated and removed the traditional firefox package, and only the snap version is available and supported. And this is fine for anyone running the desktop. But for those of us who use the server version of Ubuntu, and often need to use a browser that runs on the server itself, it has become very frustrating because of how snaps are isolated from everything, including how to access your ssh X11 forwarding. Unfortunately, there is scarce information on how to deal with this, especially for people new to the snap system. In previous versions, you would log in via ssh with X11 forwarding enabled, and after a second, you wouldd get your browser. Easy peasy. During the upgrade process, it tells you it is going to remove the traditional package and replace it with the snap, and if you do not like it you can suck an egg (I am paraphrasing, but that is the gist of it). It does not, however offer any explanation or help for people who use it remotely. And before you tell me to use some kind of remote desktop (either VNC or RDP), I would tell you that you are obviously from the Micorosoft world, and maybe you should go back there and leave the real linux people alone. I am running a server; I am not going to waste compute resources by having a desktop loaded.
So now you run firefox, and you get a less than helpful message:
Error: cannot open display: localhost:10.0
Now for people who have been around in the *nix world for a while will know this is an X11 issue where it cannot connect to the remote display, which is actually an ssh tunnel (hence the localhost). The head scratcher here is that all other non-snap X11 apps display just fine. So somehow the snap system is isolating firefox from some part of the X11 connection. It took me quite a bit of time to get the search phrasing correct to find a fairly simple solution, but not one that is necessarily obvious or intuitive. X11 uses the XAuthority system to add a small amount of security to connections, and is created when you log in and stored in a file called .Xauthority in your home directory. This has the token that allows the connection back to your ssh tunnel. So to get the snap version of firefox to know where to look for it, you have to explicitly tell it where to look. A simple solution is to just make an alias and put it in your shell’s rc file (.bashrc/.zshrc/…):
alias firefox="XAUTHORITY=$HOME/.Xauthority /snap/bin/firefox"
This sets an environment variable on invocation that is sent explicitly to the snap execution of firefox. It is not pretty, but it does let you use firefox from remote. Perhaps the firefox snap maintainers might consider putting this into the wrapper script in /usr/bin/firefox to prevent the headaches it currently causes.