Last active
June 14, 2017 19:44
-
-
Save Shaglock/2104a13e4d9a74015e1fa9356e9ee9f7 to your computer and use it in GitHub Desktop.
Active record via SSH Tunnel https://coderwall.com/p/twi-nw/using-a-database-through-an-ssh-tunnel-in-a-rails-environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ssh/gateway' | |
require 'active_record' | |
# there is no password here as the local user `user` has an SSH key stored on the remote server | |
gateway = Net::SSH::Gateway.new('domain.tld', 'user') | |
port = gateway.open('127.0.0.1', 3306, 3307) | |
ActiveRecord::Base.establish_connection( | |
adapter: 'mysql2', | |
host: '127.0.0.1', | |
username: 'dbuser', | |
password: 'dbpassword', | |
database: 'dbname', | |
port: port | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment