TITLE: Separated morphism - Hartshorne Corollary II 4.2
QUESTION [6 upvotes]: The corollary says - An arbitrary morphism $f:X\longrightarrow Y$ is separated if and only if the image of the diagonal morphism is a closed subset of $X\times_{Y} X$.
I am studying the proof of this proposition. One way is obvious. To prove the other way, we need to prove that $\Delta$ is a homeomorphism onto $\Delta(X)$ and the morphism of sheaves $O_{X\times_{Y} X}\longrightarrow\Delta_*{O_X}$ is surjective. Homeomorphism again is easy to prove. But to prove the surjectivity, Hartshorne says it is a local question. Does that mean we check it at the stalk level? I don't understand this part of the proof.

REPLY [6 votes]: An arbitrary scheme is a collection of affine schemes patched together, and an affine scheme is of the form $ \operatorname{Spec}(A) $ for some ring $A$.
To see if a map of sheaves is surjective, it is enough to check it affine-locally. Hence we can pick a neighborhood $U$ of $P$ small enough so that $\Delta(U) \subset V$ for a neighborhood $V$ of $\Delta(P)$ in $X\times X$.
Such affine neighborhoods are affine schemes, so they are of the form
$$ U= \operatorname{Spec}(A) \quad\text{and}\quad V=\operatorname{Spec}(B) $$
for some rings $A$ and $B$.
Here, locally, the map we want to prove to be surjective coincides with the homomorphism of rings
$$ B\otimes_A B \to B $$
and the fact that restriction of the morphism $\Delta$ to $U$
$$ \Delta : \operatorname{Spec}(B) = U\to U\times U = \operatorname{Spec}(B\otimes_A B) $$
is a closed embedding exactly means (by definition) that the above map of rings is surjective.