Software⏱️ 3 min read📅 2026-06-19

How to Fix: Rails + SSL error: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Rails + SSL error: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Quick Answer: Set the SSL_CERT_FILE environment variable in your .bashrc file as the user running Rails commands.

Rails and SSL errors can be frustrating, especially when trying to connect to another server. This error message indicates that the SSL connection is failing due to a certificate verification issue.

Setting up your system to handle SSL certificates correctly is crucial in resolving this issue. In this guide, we will walk you through two primary methods for fixing the 'Rails + SSL error: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed' issue.

💡 Why You Are Getting This Error

  • The primary reason for this error is that your system's trust store does not contain the necessary certificates to verify the server's identity. This can happen when the system's default trust store is incomplete or outdated.
  • Another possible cause is that the server's certificate is self-signed, which may not be trusted by default on your system.

🔧 Proven Troubleshooting Steps

Setting Environment Variables

  1. Step 1: To fix this issue, you need to set the SSL_CERT_FILE environment variable to point to the correct location of your system's trust store. On Ubuntu, this is usually located at /etc/ssl/certs/ca-certificates.crt.
  2. Step 2: Open your terminal as a user with sudo privileges (e.g., root or using 'sudo su') and run the following command: `export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt`
  3. Step 3: After setting this environment variable, you should be able to connect to the server without any issues.

Configuring Rails

  1. Step 1: Alternatively, you can configure your Rails application to use a custom SSL certificate store. This involves setting the `ssl_verify_mode` option in your Rails configuration file (usually `config/initializers.rb`).
  2. Step 2: Add the following line of code to your `config/initializers.rb` file: `SSL::VERIFY_MODE = OpenSSL::X509::VerifyMode::PEER_NAME`
  3. Step 3: This will instruct Rails to use a more permissive SSL verification mode, which may help resolve issues with self-signed certificates.

💡 Conclusion

By following one of these two methods, you should be able to resolve the 'Rails + SSL error: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed' issue. Remember to always ensure that your system's trust store is up-to-date and includes the necessary certificates for verifying server identities.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions