Suppose $L$ is a line in $\def\rt{\mathbb{R}^3}\def\rn{\mathbb{R}^n}\rt$. Let $A$ be a point on $L$ and let $\def\vv{\vec v}\vv$ be a direction vector along $L$.
Given a point $B$, how can we find $d=\text{dist}(B,L)$, the (shortest) distance from the point $B$ to the line $L$?
Let $A$ be any point in $L$ and let $\theta$ be the angle between $AB$ and $\vv$. We have \[ d=\|\vec{AB}\|\,\sin \theta = \frac{\|\vec{AB}\|\,\|\vv\|\sin \theta}{\|\vv\|} = \frac{\|\vec{AB}\times \vv\|}{\|\vv\|}.\] So \[ \text{dist}(B,L) = \frac{\|\vec{AB}\times \vv\|}{\|\vv\|}\] where $A$ is any point in $L$.
To find the distance from the point $B=(1,2,3)$ to the line \[L:\def\c#1#2#3{\begin{bmatrix}#1\\#2\\#3\end{bmatrix}}\c xyz=\c10{-1}+t\c41{-5},\quad t\in\mathbb{R}\] we can choose $A=(1,0,{-1})$ so that $\vec{AB}=\c024$ and taking $\vv=\c41{-5}$, we obtain \[ \vec{AB}\times \vv = \begin{vmatrix}\vec\imath&\vec\jmath&\vec k\\0&2&4\\4&1&-5\end{vmatrix}=\c{-14}{16}{-8}=2\c{-7}{8}{-4}\] so \[ \def\dist{\text{dist}}\dist(B,L)=\frac{\|\vec{AB}\times\vv\|}{\|\vv\|}=\frac{2\sqrt{7^2+8^2+4^2}}{\sqrt{4^2+1^2+5^2}} = \frac{2\sqrt{129}}{\sqrt{42}} \approx 3.5051.\]
The method above relies on the cross product, so only works in $\def\c#1#2#3{\begin{bmatrix}#1\\#2\\#3\end{bmatrix}}\def\rt{\mathbb{R}^3}\def\rn{\mathbb{R}^n}\def\vv{\vec v}\def\dist{\text{dist}}\rt$. The following alternative method works in $\rn$ for any $n$.
Observe that $\dist(B,L)$ is the length of the vector $\def\nn{\vec n}\nn=\vec{AB}-\def\pp{\vec p}\pp$ where $\pp=\def\proj{\text{proj}}\proj_{\vv}\vec{AB}$.
Let's redo the previous example using this method.
We have $\vec{AB}=\c024$ and $\vv=\c41{-5}$, so \[\pp=\proj_{\vv}\vec{AB} = \left(\frac{\vec{AB}\cdot \vv}{\|\vv\|^2}\right)\vv = \frac{0(4)+2(1)+4(-5)}{4^2+1^2+5^2}\c41{-5} = -\frac{18}{42}\c41{-5}=-\frac{3}{7}\c41{-5},\] so \[ \nn=\vec{AB}-\pp=\c024-(-\frac37)\c41{-5}=\c024+\frac37\c41{-5}=\frac17\c{12}{17}{13}\] so \[ \dist(B,L)=\|\nn\|=\frac17\sqrt{12^2+17^2+13^2} = \frac17\sqrt{602} \approx 3.5051.\]
Suppose that $L_1$ and $L_2$ are skew lines in $\rt$: lines which are not parallel and do not cross.
Let $\vv_1$ be a direction vector along $L_1$, and let $\vv_2$ be a direction vector along $L_2$.
The shortest distance from $L_1$ and $L_2$ is measured along the direction orthogonal to both $\vv_1$ and $\vv_2$, namely the direction of $\nn=\vv_1\times\vv_2$.
Let $\Pi$ be the plane with normal vector $\nn$ which contains $L_1$.
For any point $B$ in $L_2$, we have \[\dist(L_1,L_2)=\dist(B,\Pi) = \frac{|\vec{AB}\cdot \nn|}{\|\nn\|}\] where $A$ is any point in $\Pi$; for example, we can take $A$ to be any point in $L_1$.
To summarise: for skew lines $L_1$ and $L_2$ with direction vectors $\vv_1$ and $\vv_2$, we have \[ \dist(L_1,L_2)=\frac{|\vec{AB}\cdot \nn|}{\|\nn\|}\] where $\nn=\vv_1\times\vv_2$ and $A$ and $B$ are points with one in $L_1$ and the other in $L_2$.
What about the distance between lines which are not skew? This means that either they are non-parallel and they intersect (so that the distance between them will be zero), or they are parallel lines.
Consider the skew lines \begin{align*} x&=1+t_1\\L_1:\quad y&=2t_1\qquad (t_1\in \mathbb{R})\\z&=1+3t_1 \end{align*} and \[ L_2:\c xyz=\c 321+t_2\c1{-1}1,\quad t_2\in\mathbb{R}.\]
Note that we can rewrite the equation of $L_1$ in “vector form”, which is easier to digest: \[ L_1:\c xyz=\c 101+t_1\c123,\quad t_1\in\mathbb{R}\] The direction vectors are $\c123$ and $\c1{-1}1$, so we take $\nn$ to be their cross product: \[ \nn=\c123\times\c1{-1}1=\begin{vmatrix}\vec\imath&\vec\jmath&\vec k\\1&2&3\\1&-1&1\end{vmatrix}=\c52{-3}\] and if $A=(1,0,1)$ and $B=(3,2,1)$ then $A$ and $B$ are points with one in $L_1$ and the other in $L_2$, and $\vec{AB}=\c 220$. Hence \[\dist(L_1,L_2)=\frac{|\vec{AB}\cdot \nn|}{\|\nn\|}=\frac{2(5)+2(2)+0(-3)}{\sqrt{5^2+2^2+3^2}} = \frac{14}{\sqrt{38}}.\]
The formula $\dist(L_1,L_2)=\frac{|\vec{AB}\cdot \nn|}{\|\nn\|}$ where $\nn=\vec v_1\times \vec v_2$ works for
What about parallel lines?