Milnor's exercise: for any manifold $M$, $\mathrm{Hom}(C^\infty(M,\mathbb{R}),\mathbb{R})\cong M$ I am studying some chapters of Kolar-Michor-Slovak, Natural Operations in Differential Geometry, in particular the one on Weil bundles, where they present the famous "Milnor's exercise". They give two similar proofs, one much shorter than the other, supposedly because of omitted details. I would like to understand it better.
So we have to prove the:

Theorem For any manifold $M$, $\mathrm{Hom}(C^\infty(M,\mathbb{R}),\mathbb{R})\cong M$

Where $\mathrm{Hom}$ refers to morphisms of commutative unital algebras and $\cong$ to bijection of sets (I suppose).
Now the short proof goes like this:
Consider an homomorphism of algebras $C^\infty(M,\mathbb{R}\xrightarrow{\phi}\mathbb{R})$, by the usual short exact sequence argument, $\ker(\phi)\leq C^\infty(M,\mathbb{R})$ is an ideal of codimension $1$ (notice that such an homomorphism cannot be the zero map, since $\phi(1_\mathbb{R})=1\in\mathbb{R}$).
Now, consider the following system of subsets of $M$, where $V(f)=f^{-1}(0)$:
$$\{V(f)\mid (M\xrightarrow{f}\mathbb{R})\in \ker(\phi)\}$$
this is clearly a filter of closed sets of $M$, since $V(f^2+g^2)=V(f)\cap V(g)$.
Find a function $M\xrightarrow{f^*}\mathbb{R}\in \ker(\phi)$ which is unbounded on each non-compact closed subset of $M$ (for instance a positive proper function, such as the square of the geodesic distance w.r.t. any Riemannian metric).  Then $V(f^*)$ is a compact set contained in  $\bigcap_{f\in \ker(\phi)} V(f)$, which is then nonempty.
Let $x_0$ be one of its elements.
Then for any $f\in C^\infty(M,\mathbb{R})$ $f-\phi(f)1$ is in $\ker(\phi)$ so $(f-\phi(f)1)(x_0)=0$, and $\phi(f)=f(x_0)$.
So $x_0$ completely determines $\phi$ and the map $\phi\mapsto x_0$ is the desired bijection.
I have fetched the italicised details. What I am having trouble understanding is the bold passage. Moreover I don't see where we use the fact that the given system of sets is a filter and that $\ker(\phi)$ has codimension 1: I suspect these are relevant for the bold passage also.
Any help would be much appreciated.
 A: First we observe that what we really need in the proof is that $\bigcap_{f \in \operatorname{ker}(\phi)} V(f)\ne  \emptyset$. The proof follows from that just as you written it. Now
$$V(f^*) \supset \bigcap_{f \in \operatorname{ker}(\phi)} V(f)=\bigcap_{f \in \operatorname{ker}(\phi)} V(f)\cap V(f^*),$$
so we can use the following characterization of compactness: Any collection of closed subsets of $V(f^*)$ with the finite intersection property has nonempty intersection.
Now we prove that each finite subset $\{V(f_i)\}_{i=1}^n\subset \ker \phi$ has non empty intersection. Otherwise $g:=\sum_i f_i^2>0$ and $g\in \ker \phi$. This can't be true because if $g$ is an invertible element then $1_\mathbb{R} \in \ker \phi$( Contradiction to $\ker \phi$ has codimension $1$).
We can conclude that $\bigcap_{f \in \operatorname{ker}(\phi)} V(f)=\bigcap_{f \in \operatorname{ker}(\phi)} V(f)\cap V(f^*)$ has a non empty intersection by the compactness of $V(f^*)$.
Some observations:
The hard part is to construct $f^*$ as this shows that ${f^*}^{-1}(0)$ is compact.
Another equivalent definition of compactness of a space $X$ is: Every filter on $X$ has a cluster point. You could probably use that for the proof. We have seen in the proof that I  imitate the same reasoning used ot show $\{V(f) \mid(M \stackrel{f}{\rightarrow} \mathbb{R}) \in \operatorname{ker}(\phi)\}$ is a filter. I was not confident enough with the definitions of filters to go in that direction.
A: This is a proof of the "hard part" mentioned in  @Elad's answer.
Lemma.  A smooth manifold $M$ admits a smooth real valued function $f$ such that
$$
  \lim_{x\to \infty }f(x) = \infty ,
  $$
(in the sense that for every $a>0$, there exists a compact subset $K\subseteq M$, such that $f(x)>a$, for every $x\in M\setminus
K$)
if and only if $M$ is $\sigma $-compact.
Proof. For the  "only if" part notice that,  given $f$ as above, one has that $f^{-1}((-\infty,a])$ is compact for every real
number $a$, and
$$
  M= \bigcup_{n\in \mathbb N}f^{-1}((-\infty,n]).
  $$
Conversely, let $\{K_n\}_{n\in \mathbb N}$ be a family of compact subsets of $M$  such that   $M= \bigcup_{n\in \mathbb N}K_n$.  By a
well known trick, based on the local compactness of $M$, we may assume WLOG that each $K_n$ is contained in the interior
of $K_{n+1}$.
By Lemma (1.3.2) in https://www.math.ucla.edu/~petersen/manifolds.pdf (Smooth Urysohn Lemma), for each $n$ in $\mathbb
N$ we may choose a nonegative smooth function $f_n$ vanishing on $K_n$ and taking on the value 1 on $M\setminus \text{int}(K_{n+1})$ (and
hence also on $M\setminus K_{n+1}$).
Defining
$$
  f(x) = \sum_{n=1}^\infty  f_n(x), \quad \forall x\in  M,
  $$
we claim that, for every $x$ in $M$,  there exists   a neighborhood $V$ of $x$,  and a natural number $m$, such that
$f_n=0$ on $V$, for every $n\geq m$.
To see this, find some $i$ such that $x\in  K_i$.   It then suffices to take
$V=\text{int}(K_{i+1})$ and $m=i+1$.
This said, it is clear that the  above function $f$ is well defined and smooth.
To see that  $\lim_{x\to \infty }f(x) = \infty $, observe that if $x\not\in  K_{m+1}$, then  surely $x\not\in K_{n+1}$, for  every $n\leq m$,  whence
$$
  f(x) \geq   \sum_{n=1}^m f_n(x) = m.
  $$
This completes the proof of the Lemma.  QED

Back to the question, let us assume that  $M$ is $\sigma $-compact, so we may pick  $f$  as in the
Lemma.
Setting
$$
  f^*=f-\phi(f)1,
  $$
one has  that $f^*\in \text{Ker}(\phi)$, and clearly also   $\lim_{x\to \infty }f^*(x) = \infty $, so we have that
$$
  V(f^*) =   {f^*}^{-1}(0)
  $$
is compact, as desired.
