You have to know that #color (red) (y'=m)# (the slope) and also the equation of a line is #color (blue) (y=mx+b)#
#y=(x-1)(x^2-2x-1)=x^3-2x^2-x-x^2+2x+1#
#=>y=x^3-3x^2+x+1#
#y'=3x^2-6x+1#
#y'=m=>m=3x^2-6x+1# and at #x=2#, #m=3(2)^2-6(2)+1=12-12+1=1#
#y=x^3-3x^2+x+1# and at #x=2#, #y=(2)^3-3(2)^2+2+1=8-12+3=-1#
Now, we have #y=-1#, #m=1# and #x=2#, all we have to find to write the equation of the line is #b#
#y=mx+b=>-1=1(2)+b=>b=-3#
So, the line is #y=x-3#
Note that you could also have found this equation by using #color (green) (y-y_0=m(x-x_0))# with your point #(2,-1)# since #x_0=2# and #y_0=-1#
#y-y_0=m(x-x_0)=>y-(-1)=1(x-2)#
#=>y+1=x-2#
#=>y=x-3#
Hope this helps :)