Gitlab 500 error when add ssh key

My friend who ask for email problem send me another email. He told me that he already move his gitlab server to another because he see better offer (cheaper vps with better feature). The transfer job taken by his co worker that taking vacation now.  The problem is simple .

When he try to add ssh key to his gitlab account he got this error : 500

Gitlab 500 error when add ssh key - something error

He never see this kind of error and ask me to see it. I also never see this but I promise to help him.

After search around the log file ( He use gitlab 7.1.1 on Ubuntu 14.04 server ) I can see the real problem is came from memory.

# tail -f /var/log/gitlab/gitlab-rails/production.log
Parameters: {“utf8″=>”✓”, “authenticity_token”=>”nKCheVvcyuhTrKUTrWbin9VOYpVPJEWk6lAJO63Lu9o=”, “key”=>……………………………….

…………………………………………….

………………………………………………………………….”}}
Completed 500 Internal Server Error in 137ms

Errno::ENOMEM (Cannot allocate memory – ssh-keygen):
lib/gitlab/popen.rb:23:in `popen’
app/models/key.rb:78:in `block in generate_fingerpint’
app/models/key.rb:75:in `generate_fingerpint’
app/controllers/profiles/keys_controller.rb:20:in `create’

Yes, the process fail due to memory. He use 1GB vps which sufficient but his friend forget to add swap.

# free
total       used       free     shared    buffers     cached
Mem:       1017920     902120     115800      25508      12572     109512
-/+ buffers/cache:     780036     237884
Swap:            0          0          0

Time to create swap

# dd if=/dev/zero of=/swapfile bs=2048k count=1000
1000+0 records in
1000+0 records out
2097152000 bytes (2.1 GB) copied, 6.39124 s, 328 MB/s

# mkswap /swapfile
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=b94e5899-2093-42da-8eec-a502d1148870

Activate swap

#swapon /swapfile

# swapon -s
Filename                Type        Size    Used    Priority
/swapfile                               file        2047996    0    -1

# free -m
total       used       free     shared    buffers     cached
Mem:           994        919         74         24          3        152
-/+ buffers/cache:        763        230
Swap:         1999          0       1999

Make it permanent. Each time server reboot no need to configure.

#nano /etc/fstab

add this line :

/swapfile       none    swap    sw      0       0

others command :

#chown root:root /swapfile
#chmod 0600 /swapfile

#echo 10 | sudo tee /proc/sys/vm/swappiness
#echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

Those command basically for securing swap file and set swap ‘involve’.

Time to retest add ssh key.

Gitlab 500 error when add ssh key : ssh key successfully added after increase swap

Finish.

Its not vps vault but his friend vault 🙂