2. It is safe to say $a,b\not = 0$. Consider the set $S=\{ an+bm|n,m\in \mathbb{Z} \}$. Now if $x,y\in S$ then $x+y,x-y\in S$ and $xz\in S$ where $x\in S,z\in \mathbb{Z}$. Since $S$ has a positive element (that is easy to show) it has a least positive element $c$. Now by division algorithm, $a=qc+r$ where $0\leq r < c$. Thus, $r=a-qc \in S$ because of closure properties above. But then $r=0$ because $c$ is least. So $c|a$ similarly $c|b$.