Solution
Use the cut command to forcibly disconnect the user from the port before changing the port security
mode.
[Device-GigabitEthernet1/0/1] quit
[Device] cut connection interface gigabitethernet 1/0/1
[Device] interface gigabitethernet 1/0/1
[Device-GigabitEthernet1/0/1] undo port-security port-mode
187