I am new to Linux and trying out Ubuntu 11.10. I am setting up a SSH server and one of the instructions asks me to edit sshd_config file using vi.

In vi, I can't remember what happen (it's all a blur now) but the up/down keys turn into capital alphabets. After a bit, I give up, search on SO, and the solution is to use vim, not vi. So I try to exit vi (didn't' remember what I did) but I got back to the console.

Then, when I enter sudo vim /etc/ssh/sshd_config it says a swap file exist. Using ls -A only lists the sshd_config and I don't see a ssh_confid.swp file anywhere.

ps -ef | grep vi

shows this:

root      2914  2135  0 10:45 pts/0    00:00:00 sudo vi /etc/ssh/sshd_config
root      2915  2914  0 10:45 pts/0    00:00:00 vi /etc/ssh/sshd_config
user       4066  2135  0 11:28 pts/0    00:00:00 grep --color=auto vi

Then so I try to kill the processes, by using sudo kill 2135 2914 2915 and nothing happens. HOw do I get out of this mess?


  • 3
    In Ubuntu Linux, vi and vim are the same program, but one is a symbolic link to the other (and vi actually sets some old vi-style keys I think). The .swp file is a vim thing, and you can see it in /etc/ssh/ by typing ls -a, which will show hidden files. You can delete the swp file, or use an editor like pico/nano. – wkl Feb 29 '12 at 16:38
  • In such a condition, you can remove the swp file by hitting D when you get the message. – kamae Feb 29 '12 at 18:43

First off, if

sudo kill <pid>

does not kill a process after several attempts, try

sudo kill -9 <pid>.

That will force the process to end.

Next, execute a

ls -a /etc/ssh | grep ".swp"

to look for any swap files. You'll probably find a file called ".sshd_config.swp", so you'll want to delete that before trying to edit /etc/ssh/sshd_config.

sudo rm /etc/ssh/.sshd_config.swp

If you want to learn more about Vim, here are some links to Vim tutorials. However, I would recommend nano for someone who is brand new to Linux.

The Interactive Vim Tutorial

Graphical vi-vim Cheat Sheet and Tutorial


You can exit vim without saving by typing :q!.
If you want to save the file, type :wq or :x.
The swp file created by vim is a hidden file begin with .(dot).
I hope it'll help you.


Based on the process listing, you got into a subshell. If you type exit in the shell you were first in, then you should get back to the vi session. Then you can either continue editing in vi or exit and run a more intuitive, less powerful editor like nano as romainl suggests.


The solution to the underlying problem is to use nano or Gedit, if you have access to a GUI, instead of vi or vim. Vi and Vim are two (related) complex and powerful programs not really suited for beginners.

It's certainly useful to learn Vi(m)'s basics if you intend to spend a lot of time coding in Linux (or elsewhere) but don't bother trying to learn it for editing a few lines every blue moon.

The solution to the immediate problem is:

$ sudo killall vi

which is going to kill all running instances of vi after asking for your password.

After you are done, use the same commands you used but replacing vi with nano which is a lot less powerful and a lot more intuitive with its menu at the bottom.

$ sudo nano /etc/ssh/sshd_config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.