The points on the infinite right circular cylinder are at distance $r$ from the axis of the cylinder. The distance between point $\vec{p}$ and line through $\vec{p}_1$ and $\vec{p}_2$ is
$$d = \frac{\left \lvert (\vec{p} - \vec{p}_1) \times (\vec{p} - \vec{p}_2) \right \rvert}{\left \lvert \vec{p}_1 - \vec{p}_2 \right \rvert}$$
so we can square that to get our equation describing an infinite right circular cylinder of radius $r$ whose axis passes through points $\vec{p}_1$ and $\vec{p}_2$:
$$r^2 = \frac{\left \lvert (\vec{p} - \vec{p}_1) \times (\vec{p} - \vec{p}_2) \right \rvert^2}{\left \lvert \vec{p}_1 - \vec{p}_2 \right \rvert^2}$$
That can be written using Cartesian coordinates as
$$r^2 = \frac{ \left ( (y-y_1)(z-z_2) - (z-z_1)(y-y_2) \right )^2 }{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2 } + \frac{ \left ( (z-z_1)(x-x_2) - (x-x_1)(z-z_2) \right )^2 }{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2 } + \frac{ \left ( (x-x_1)(y-y_2) - (y-y_1)(x-x_2) \right )^2 }{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2 }$$
which we can convert to standard form by multiplying by the right-hand-side denominator, and moving all to the same side:
$$\left ( (y-y_1)(z-z_2) - (z-z_1)(y-y_2) \right )^2 + \left ( (z-z_1)(x-x_2) - (x-x_1)(z-z_2) \right )^2 + \left ( (x-x_1)(y-y_2) - (y-y_1)(x-x_2) \right )^2 - r^2 \left ( (x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2 \right ) = 0$$
I have at my Wikipedia talk page the equations to locate the intersection between a line passing through origin and an arbitrary right circular cylinder; without caps, with flat end caps, or with spherical end caps. The key point is that when the ray (or line we are testing intersection for) passes through origin (so we use an unit vector $\hat{n}$, $\lvert\hat{n}\rvert=1$, to describe the line or ray), the equations become rather straightforward.
If the underlying problem is related to grinding spheres using a grinding wheel -- a cutting plane, essentially -- then a simplified coordinate system where origin is the sphere origin, and $\hat{z}$ is along the rotation axis, makes for easy calculations. Consider this illustration:
The contact point scribes a circle around the axis of rotation. We can describe this circle using a single scalar, $d$, which is the signed distance from the origin to the plane of that circle, along the axis of rotation. If the circle is not on the surface of the sphere, but perhaps inside it, then we need a second scalar, $r$, to describe the radius of the circle (around the axis of the rotation).
If the radius of the sphere is $R$, then on the surface of the sphere $r = \sqrt{R^2-d^2}$, of course.
If we include the cutting or abrasion done by the wheel, then two pairs of scalars are needed: $(d_1,r_1)$ and $(d_2,r_2)$. If we assume the grinding wheel is planar, and stays at a fixed location with a perfect cut for at least one rotation of the sphere, the removed section of the sphere leaves a flat facet. Mathematically, $$r(d) = r_1 + \left ( d - d_1 \right ) \frac{r_2 - r_1}{d_2 - d_1}$$
where $d_1 \le d \le d_2$. Remember, $d$ is the distance along the axis of rotation, and $r$ the circle radius (around a point on the axis of rotation, at distance $d$ from the center of the sphere); that is why the dependence above is linear too.
If the axis of the grinding wheel always intersects the rotation axis, and you call up $z$ and right $x$ in the above diagram, then $(d,r) = (z,x)$, and the primary problem (surface of revolution caused by grinding, or shape of the "sphere" after several grinds) reduces to planar (2D) vector calculus.
If we also have the axis of rotation $\hat{n}$ in some fixed sphere coordinate system, it is easy to calculate the "ribbons" each grind cuts into the sphere, either parametrically (using say $0 \le u \le \pi$ along the circular ribbon, and $0 \le v \le 1$ across the ribbon -- useful for visualization) or algebraically.
Best Answer
You can divide the line into three segments. The line is divided by the two planes of the bottom and top disks of the cylinder. See the image below (1) for example.
Each segment will find the minimum distance independently from each other, and only the minimum distance between all three segments will be chosen. To calculate the minimum distance of each segment, do:
First line segment (blue line): calculate the minimum distance between this segment and the bottom disk of the cylinder (I'm still using an iterative numerical method here using the distance between a point and a disk as objective function).
Second line segment (green line): project this line segment and the cylinder to the plane orthogonal to the main axis of the cylinder (as pointed by @Stefano). Find the point on this projected line that is closest to circle created by the cylinder projection.
Third segment (red line): same as the first segment, but now use the top disk.
Problem with this approach: Imagine you have a line that is really small, almost like a single point, direct below the top disk, inside the cylinder that never crosses to the top side. This approach will calculate the minimum distance as per the
Second segment
before, (distance circle and line), but its wrong because the minimum distance should be from this line segment to the top disk.