How to connect to server with only username and public ssh key? - django

I want to use a batch file to connect to a amazon server by using the ssh private or public key.
I have tried
open sftp://user:password#example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
psftp fred#server.example.com
in the script but I am not able to connect to the server. I am getting this error.
disconnected no supported authentication methods available (server sent publickey)
I am able to connect it from putty. I want a batch file to connect to the server and restart the django project in that.
If I am able to connect then I just need to go the path of my django project and run the command
manage.py runserver

ssh -i PrivateKey.pem username#server.example.com

Related

How to copy folder from remote server (digital Ocean) to local computer

I am trying to copy a folder from my digital Ocean server to my computer.
I have successfully connected as root to my server and I have the ssh Public key setup
I use command root#my-server_ip to connect successfully.
When I try to copy a file like
scp -r root#my-server_ip:/file/path/ /where/to/put
I get this error Permission denied (publickey).
I can't figure out what the heck is the issue
Permission denied occurs when the server is not able to validate the incoming connection. You need to provide the path to your identity file (ssh key) explicitly when making a request through scp.
Something like this:
scp -i <path_to_identity_file> -r root#my-server_ip:/file/path/ /where/to/put

GCE SQL proxy connecting to wrong sql ip

I am having a strange issue with my GCE Proxy.
I used to have a docker image with an application that would use the GCE proxy to connect to the mysql database(second generation). Everything worked fine, but I had to stop the services for like a month.
Now I need them back up and for some reason I am not able to connect to the dabase(configuration did not basically chang, and I am using the same docker image with the code)
On closer inspection I see in logs:
Caused by: java.sql.SQLException: Access denied for user 'my-usr'#'cloudsqlproxy~SOME_IP' (using password: YES)
The problem is, that the "SOME_IP" is not actually the sql instance IP and I have no idea from where that IP is coming from.
Does anyone have an idea on how to fix this issue?
I did try to:
-recreate the database user
-recreate the service account
Any advice is welcomed
You can use Cloud SQL proxy to connect your mysql instance, see the step by step below:
Download the proxy:
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
Make the proxy executable:
chmod +x cloud_sql_proxy
Using the proxy to connect to multiple instances
./cloud_sql_proxy -instances=yourProject:us-central1:myInstance=tcp:3306,yourProject:us-central1:myInstance2=tcp:3307 &
mysql -u myUser --host 127.0.0.1 --port 3307
Try to connect your database
mysql -h127.0.0.1 -u$YOUR_CLOUD_SQL_USER -p$YOUR_CLOUD_SQL_PASSWORD
Hoping it helps you!

SSH tunnelling to a remote server with django

I'm trying to set up an SSH tunnel to access my server (currently an ubuntu 16.04 VM on Azure) to set up safe access to my django applications running on it.
I was able to imitate the production environment with Apache WSGI and it works pretty good but since I'm trying to develop the application I don't want to make it available to broader public right now - but to make it visible only for a bunch of people.
To the point: when I set up the ssh tunnel using putty on Windows 10 (8000 to localhost:8000) and I run http://localhost:8000/ I get the folowing error:
"Not Found HTTP Error 404. The requested resource is not found.".
How can I make it work? I run the server using manage.py runserver 0:8000.
I found somewhere that the error may be due to the fact that the application does not have access to ssh files, but I don't know whether that's the point here (or how to change it).
Regards,
Dominik
After hours of trying I was able to solve the problem.
First of all, I made sure putty connects to the server and creates the desired tunnel. To do that I right-clicked on the putty window (title bar) and clicked event log. I checked the log and found the following error:
Local port 8000 forwarding to localhost:8000 failed: Network error:
Permission denied
I was able to solve it by choosing other local port (9000 instead of 8000 in my instance).
Second of all, I edited the sshd_config file: sudo vi etc/ssh/sshd_config
and added these three lines:
AllowAgentForwarding yes
AllowTcpForwarding yes
GatewayPorts yes
I saved the file and restarted the ssh service:
sudo service ssh stop
sudo service ssh start
Now when I visit localhost:9000 everything works just fine.

Digital ocean on Laravel Forge - Unable to load key (navicat)

Im pulling my hair out with this one. I've managed to get a site running on Digital Ocean through Forge and also SSH into the server so I know that the SSH keys are setup correctly.
But when trying to connect via Navicat, I keep getting the error "Unable to load key". Does anyone know what this is in reference to or what the problem is.
regards
There is an answer from 2015 on Navicat forum, indicating there could be issue with ssh key support.
If you can connect via ssh, do an ssh tunnel to your server manually:
ssh -v servername -L 3306:127.0.0.1:3306 -N
Afterwards, you connect to remote mysql as it was on your localhost (you should not have one running on 3306, otherwise map to another local port)

How do I connect to aws ec2 server from chromebook using the secure shell extension?

I am trying to connect to my ec2 instance from my chromebook using the secure shell extension but I keep getting the following error:
Loading NaCl plugin... done.
ssh: connect to host (public DNS) port 22: Connection refused
NaCl plugin exited with status code 255.
I have been following the steps on this site but with 0 success.
http://www.mattburns.co.uk/blog/2012/11/15/connecting-to-ec2-from-chromes-secure-shell-using-only-a-pem-file/
Help please.
If you're doing this on your chromebook, you should have developer mode enabled so that you can enter the console and execute Linux commands. Once developer mode is enabled, enter the console with ctrl+alt+t and then type in shell.
First you'll want to change the permissions of your .pem key. The ssh keygen won't run if the permissions aren't restricted enough.
sudo chmod 400 myKeyPair.pem
Next you'll want to generate your own public key with ssh-keygen like mentioned in the other links.
ssh-keygen -y -f myKeyPair.pem > myKeyPair.pub
After this, you'll want to create a file with no extension and the private key pair inside.
touch myKeyPair
After this, copy the contents of the .pem file to the file with no extension, myKeyPair.
sudo cat myKeyPair.pem > myKeyPair
Next you'll want to open up the secure shell extension, which can be found here.
Enter your connection information for your machine and don't forget to specify the port number. When it comes to importing the key pair, select both the myKeyPair.pub and the myKeyPair files using ctrl.
That's it, you should be connected!