Let $x_0, y_0, z_0$ be the current values of $x, y, z$.
An equation of the form $ax + by + cz = N$ specifies a plane in space. Let your plane be $P$. So your problem is equivalent to the following one: in space, given a point $(x_0, y_0, z_0)$ and a plane $P$, find the point on $P$ that is closest to $(x_0, y_0, z_0)$.
The closest point will be the point you get by dropping a perpendicular line from $(x_0, y_0, z_0)$ to $P$ and seeing where it lands. (This must be the closest because a straight line is the shortest distance between any two points!)
What I just described is also called the orthogonal projection of a point onto a plane. It's solved e.g. here.
As charlestoncrabb mentions, this is equivalent to the method of least squares because we measure distance in space by $\sqrt{(x_1 - x_0)^2 + (y_1 - y_0)^2 + (z_1 - z_0)^2}$. So that's the "default" meaning of "close to" in this context, oddly enough. If want to measure "close to" some other way, you can use more general optimization methods (like Lagrange multipliers).