Download a file remote server that uses different port and private key - download

I need to download a file from a remote server to my local. The SSH is running on a non-standard port and the remote server required a private key to connect to it from local.
I know how to achieve it separately:
For non standard port it is:
scp -P 2222 username#example.com:/backup/file.zip /local/dir
For server using private key it is:
scp -i private_key.pem username#example.com:/backup/file.zip /local/dir
But how can I download a file that require connecting to a non-default port as well as uses pem file (private key file)?
Any help would be appreciated.
Thanks

scp -i private_key.pem -P 2222 username#ip_address:/backup/file.zip .
This worked for me.

Related

How to change the ssh port connection on Windows?

I am trying to connect to GitLab with an ssh key from a Windows laptop. The problem is the port of the repository has changed, and I cannot manage to change the default port 22 on the config.
I have tried with a mac laptop and it worked by editing the config file, but I cannot do the same on Windows. I created a config file with touch config and added this
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 1122
But it does not work, terminal says it is still connecting to port 22:
C:\Users\parko>ssh -T git#gitlab.com
kex_exchange_identification: read: Connection reset
C:\Users\parko>ssh -T git#gitlab.%myRepository%.com
ssh: connect to host gitlab.%myRepository%.com port 22: Connection timed out
I also tried a solution that I found in an article to change the port directly on the command when trying to connect, but it also did not work:
C:\Users\parko>ssh -T git#gitlab.%myRepository%.com:1123
ssh: Could not resolve hostname gitlab.%myRepository%.com:1123: No such host is known.
Any idea what can be happening?
Thanks in advance.
Like #ewong said, I had to add the port with the -p parameter instead of at the end of the command
ssh -p [port number] -T git#[gitlab URL]
for me it was:
C:\Users\parko>ssh -p 1123 -T git#gitlab.%myRepository%.com

How Connect Unix Socket via SSH Tunnel in Datagrip

How can I connect to a MySQL server via SSH Tunnel and get from the server the UNIX socket in Datagrip?
I found this partial solution, that helps me to configure SSH Tunnel but not get the socket file from the server.
How to connect to database through SSH using DataGrip
The server is MariaDB and I tried to use this information too but doesn't work
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360010247880-How-to-connect-to-mariadb-via-unix-socket-
unix socket is not forwarded via SSH tunnel unless you perform some additional steps. the best approach is to use socat. something like that before connection:
/usr/bin/socat "UNIX-LISTEN:$SOCKET_DIR/mariadb-remote1.sock,reuseaddr,fork" \
EXEC:'/usr/bin/ssh -F /etc/sshssh_config -l root <remote1 host> -p 22 /usr/bin/socat STDIO UNIX-CONNECT\:/run/mariadb/mariadb.sock'
Here and here you can find more useful information.

How to use an remote instance as "proxy" to ssh port

In my local network I currently can't ssh to bitbucket:
telnet bitbucket.org 22 fails.
But I can ssh to an remote ubuntu instance that can ssh to bitbucket (the command above works).
How can I configure my connectivity to make my traffic to bitbucket port (22) go through this intermediary instance?
I tried running the command below but did not work:
sudo ssh -i mykey -N -L 22:remote_instance:22 ubuntu#remote_instance (ps: remote_instance can access bitbucket with port 22).
Thanks :)

Unable to connect to EC2 server with my MacBook

I am unable to connect to EC2 (CentOs) from my MacBook. When I connect it from ubuntu machine, it will be connected. Currently, I got the following the following error:
ec2 ssh sign_and_send_pubkey: no mutual signature supported Account locked due to 290 failed logins
How can I solve the problem?
I have tried the following command:
ssh -i key.pem ec2-user#ip
I was locked out and couldn't access the machine to enter in the suggested answer's change to ssh config.
I added the following argument to the ssh call -o PubkeyAcceptedKeyTypes=+ssh-rsa and it worked.
Example:
ssh -i "keypair.cer" -o PubkeyAcceptedKeyTypes=+ssh-rsa ec2-user#ip
Note: the ssh call will accept both .cer and .pem filetypes.
edit or create the file ~/.ssh/config and add the following content:
Host *
PubkeyAcceptedKeyTypes=+ssh-dss
After that, try again.

Setup passphraseless ssh to localhost on OS X

I'm trying to get Hadoop's Pseudo-Distributed Operation example (http://hadoop.apache.org/common/docs/stable/single_node_setup.html) to work on OS X Lion, but am having trouble getting the ssh to work without a passphrase.
The instructions say the following:
Setup passphraseless ssh
Now check that you can ssh to the localhost without a passphrase: $
ssh localhost
I'm getting connection refused:
archos:hadoop-0.20.203.0 travis$ ssh localhost
ssh: connect to host localhost port 22: Connection refused
If you cannot ssh to localhost without a passphrase, execute the
following commands:
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
After this step I am still getting connection refused. Any ideas???
Sounds like you don't have SSH enabled. Should be in the network settings control panel somewhere.
You go to "System Preferences > Sharing > Remote Access" and there's a list of authorized users. Change it to "All Users".
That's solves this problem.
Check the permissions on your .ssh directory. Some ssh implementations require that the directory be chmod 700. Otherwise, they just ignore it.
Also, check the output of
ssh -v localhost
to see how the ssh client is trying to connect. The output is very detailed, and will help you decide if it's an authentication problem.
I had the same issue.
Please check if the ssh server is running or not.
If yes, open the /etc/init.d/ssh_config and /etc/init.d/sshd_config files. The issue is that the server is running on a different port and the client is pointing to different port.
Before this please ensure that openssh-server and client are installed.
I had the same problem and i solved it the following manner :
SSH is activated.
ssh -v localhost (as stated by Herko)
In the ouput, i identified that the authentication method by DSA is not supported.
debug1: Skipping ssh-dss key /Users/john/.ssh/id_dsa - not in PubkeyAcceptedKeyTypes
I simply re-generate an ECDSA keys and remove the DSA key pairs.
After the keys generation, the procedure given on Hadoop documentation holds.
Therefore, it is important to check, if the authentication method is supported by the Openssh configuration.

Resources