We apply the theory of generalized polynomial identities with automorphisms and skew derivations to prove the following theorem: Let A be a prime ring with the extended centroid C and with two-sided Martindale quotient ring Q, R a nonzero right ideal of A and $$\delta $$ δ a nonzero $$\sigma $$ σ -derivation of A, where $$\sigma $$ σ is an epimorphism of A. For $$x,y\in A$$ x , y ∈ A , we set $$[x,y] = xy - yx$$ [ x , y ] = x y - y x . If $$[[\ldots [[\delta (x^{n_0}),x^{n_1}],x^{n_{2}}],\ldots ],x^{n_k}]=0$$ [ [ … [ [ δ ( x n 0 ) , x n 1 ] , x n 2 ] , … ] , x n k ] = 0 for all $$x\in R$$ x ∈ R , where $$n_{0},n_{1},\ldots ,n_{k}$$ n 0 , n 1 , … , n k are fixed positive integers, then one of the following conditions holds: (1) A is commutative; (2) $$C\cong GF(2)$$ C ≅ G F ( 2 ) , the Galois field of two elements; (3) there exist $$b\in Q$$ b ∈ Q and $$\lambda \in C$$ λ ∈ C such that $$\delta (x)=\sigma (x)b-bx$$ δ ( x ) = σ ( x ) b - b x for all $$x\in A$$ x ∈ A , $$(b-\lambda )R=0$$ ( b - λ ) R = 0 and $$\sigma (R)=0$$ σ ( R ) = 0 . The analogous result for left ideals is also obtained. Our theorems are natural generalizations of the well-known results for derivations obtained by Lanski (Proc Am Math Soc 125:339–345, 1997) and Lee (Can Math Bull 38:445–449, 1995).