Jittery Camera 3D

I want my camera to follow the player along the Z axis, with a specified distance for the camera to be behind the player but my camera keeps on shaking when the player moves along the z axis. What can I do to fix this?

Here’s my code:

  mainCamera.transform.position = new Vector3(mainCamera.transform.position.x, mainCamera.transform.position.y, player.transform.position.z - offset);

Make it Lerp.
camera.position = Vector3.Lerp(camera.position, target.positio, lerpSpeed * Time.deltaTime)