Given a ring $R$ which is UFD and if $\gcd(a,b)=d$ then $\exists r,s$ such that $ra+sb=d , \forall a,b\in R$, then $R$ is a PID.
Let $\gcd(a,b)=d$ .
$(d)=(a,b)$
Since $d=ra+sb$, we get that $(d)\in (a,b)$. Since $d=\gcd(a,b)\implies d|a,d|b$. Say $a=da',b=db'$. So let $k\in (a,b)\implies k=a\alpha+b\beta $ for some $\alpha, \beta \in R\implies k=da'\alpha+db'\beta\implies k=d(a'\alpha+b'\beta) \implies k\in (d)\implies (d)=(a,b)$.
We can essentially repeat the same proof for any finitely generated ideal. That is, if I have a finitely generated ideal $I=(a_1,\dots,a_k)=(\gcd(a_1,\dots,a_k))$. Note, we do have to show that if $gcd(a_1,\dots,a_k)=d$ then $\exists$ $b_1,\dots, b_k$ such that $d=\sum a_ib_i$. \newline We show it for $k=3$ and then the higher cases is just same.
If $gcd(a_1,\dots,a_3)=d$ then $\exists$ $b_1,\dots, b_3$ such that $d=\sum a_ib_i$
Note that $\gcd(a_1,a_2,a_3)=\gcd(\gcd(a_1,a_2),a_3)$. Now use bezouts for two terms.
So, if we have a finitely generated ideal, we get an element which generates the ideal.
If $I$ is an ideal in $R$ then $I$ is finitely generated.
Suppose there an ideal $I$ such that it is not finite generated and hence, is proper. Then we will construct an increasing chain of proper ideals. This will contradict the factorization terminating thus contradicting that $R$ is a UFD. But consider $a_1\in I$. Note that for $ a_1\in I,\exists a_2\in I $ such that $(a_1)$ is proper sub ideal of $(a_1,a_2)$. If not then $\forall a_2\in I, (a_1,a_2)=(a_1)\implies a_2\in (a_1)\forall a_2\in I\implies I$ is finitely generated. So, since $(a_1,a_2)$ is finitely generated ideal, it is of the form $(i_1)$ for some $i_1\in I$. Again, we get that $\exists a_3$ such that $(a_1,a_2)$ is proper sub ideal of $(a_1,a_2,a_3).$ And continue. So our increasing chain of ideals is $(a_1),(a_1,a_2),(a_1,a_2,a_3),\dots $
So, $R$ contains only finitely generated ideals and any finitely generated ideal is generated by some element. So $R$ is a PID.