sed. Use the tools provided for interfacing with that file instead.
In this case,
chsh, or possibly the more general
On most systems:
$ sudo chpass -s /sbin/nologin mysql
$ sudo chsh -s /sbin/nologin mysql
You don't want to edit
sed (or with
emacs), and definitely not with
User @JdeBP reminds me about the
vipw utility in the comments below. This is a special command, much like
visudo, that lets you edit the
/etc/passwd while taking care of file-locking etc. It also does consistency/syntax checking of the saved file before installing the new password file in place of the old one. Refer to the manual for
vipw on your system for more information. This is the only safe way to edit the passwords file by hand.
Also note that on some Unix systems, the default login shell is set by other means than through the password file. On OS X, for example, ordinary users don't even have an entry in