From RootdevWiki
KDE Tips and Tricks
Lock your desktop from the command line
In KDE 3.x you can lock your desktop remotely by using the dcop server. First of all identify your sessions as follows:
dcop --user <username> --list-sessions
This should output something like the following (I have multiple sessions on different hosts with NFS mounted home dirs):
$ dcop --user craig --list-sessions Active sessions for user /home/users/craig : .DCOPserver_host1__0 .DCOPserver_host2__0
To correctly call your session just drop the .DCOPserver_
To lock the specified session:
dcop --user <username> --session host0__0 kdesktop KScreensaverIface lock