I am trying to scp files to and from a remote server through an intermediate host. I can successfully do the following:
Scp from remote server (lome.1470mad.mssm.edu) to local desktop through intermediate host (shell.mssm.edu):
scp -r -o 'Host lome.1470mad.mssm.edu' -o 'ProxyCommand ssh hernam13#shell.mssm.edu nc %h %p' matt#lome.1470mad.mssm.edu:/dir1/matt/ .
But I am having trouble copying files in the other direction (from local host to lome.1470mad.mssm.edu through the intermediate host (shell.mssm.edu).
Can someone please clarify on how to do this?
Thanks!
It should just work the other way round (switching source and destination):
scp -r -o ProxyCommand="ssh -W %h:%p hernam13#shell.mssm.edu" local.file matt#lome.1470mad.mssm.edu:/dir1/matt/
The -o 'Host lome.1470mad.mssm.edu' is no useful. The ProxyCommand ssh hernam13#shell.mssm.edu nc %h %p is better to use -W switch to ssh. If it does not work, what errors you get?
Related
I have three remote, PC_A have the python code while PC_B are on different network have the database and PC_C also have the database which have the same network with PC_A
I was able to load the data from PC_A to PC_C in script like the following:
IN PC_A,
#!/bin/sh
# echo "i am in bin testing"
/home/user/env/bin/python3.8 /home/user/load_to_db.py -e IP_OF_PC_C
And to load the data to PC_B , i open a SSH tunnel among PC_A and PC_B,
i was able to load the data to PC_B if i do the following:
ssh -L 9200:127.0.0.1:9200 -L 5601:127.0.0.1:5601 user#IP_PC_B -p 30020
which 30020 is the SSH portt, 5601/9200 are the ElasticSearch and Kibana port
and then run (in PC_A) the script:
#!/bin/sh
# echo "i am in bin testing"
/home/user/env/bin/python3.8 /home/user/load_to_db.py -e localhost
I fail if i write the following in the
#!/bin/sh
ssh user#PC_B -p 30020
/home/user/env/bin/python3.8 /home/user/load_to_db.py -e PC_B
I was wondering how i write the above to script to transfer the data to PC_B with SSH
Thanks
i google a bit in "using local port forwarding in background" and "kill the ssh process" , i do a little test and below is what i need
ssh -N -f -L 9200:127.0.0.1:9200 user#IP_OF_PC_B -p 30020
do python code in PC_A
kill $(ps aux | grep ssh | grep 9200 | awk '{print $2}')
I have a scenario where I need to copy production database to my dev database on daily basis. Both are different servers. What I have thought of writing a cronjob that will do the stuff. I have written a php script. I am connecting to remote production server via sshpass, taking its dump and then populating that dump.
exec("sshpass -p 'mypassword' ssh root#IP_ADDRESS:PORT");
exec("mysqldump -u root -p DB > production_dump.sql");
exec("mysql -u root -p test < production_dump.sql");
But at first line it throws error of stating
ssh: Could not resolve hostname IP_ADDRESS:PORT: Name or service not known
I have tried given solution on internet but non of them worked. Can any on please explain what I am doing wrong?
Your command is failing because it's not formatted right. You need to use one of the following formats:
sshpass -p 'mypassword' ssh root#IP_ADDRESS PORT
sshpass -p 'mypassword' ssh root#IP_ADDRESS -p PORT
sshpass -p 'mypassword' ssh ssh://root#IP_ADDRESS:PORT
However, I'm not sure if the rest of the script will work, especially if it starts asking for a password. A bash script would be the way to go.
I'm trying to import an .sql file into a new database on my AWS RDS. the RDS can only be reached by BastionHost via SSH and is not publicly available.
Right now I copy the file to the Bastion Host like that:
scp -i key.pem ~/databases/Datenmodell_init.sql ubuntu#ec2-88-255-112-
102.eu-west-1.compute.amazonaws.com:~/ubuntu/Datenmodell_init.sql
But I want to recreate the database directly without copying the file to the EC2 instance; the usual command doesnt work, obviously, since the SSH part is missing:
mysql -h mydb.co4qgzotzpzu.eu-west-1.rds.amazonaws.com -u masteruser -p new1 < ~/databases/Datenmodell_init.sql
How can I achieve the import of the .sqlfile through the Bastion Host to the RDS via Terminal?
Merci A
You should be able to set up an SSH tunnel and then use that to connect to the db:
ssh -i key.pem -L 10000:mydb.co4qgzotzpzu.eu-west-1.rds.amazonaws.com:3306 ubuntu#ec2-88-255-112-
102.eu-west-1.compute.amazonaws.com -N
mysql -h localhost -P 10000 -u masteruser -p new1 < ~/databases/Datenmodell_init.sql
There's a full explanation at eg https://medium.com/#michalisantoniou6/connect-to-an-aws-rds-using-an-ssh-tunnel-22f3bd597924
I have a linux box with web serverthe has 2 running services:
web proxy (listens ports 80, 443)
apache (listens port 8080)
The users for proxy can register through web interface. I must give access to proxy only to the registered clients with certain IPs. Proxy is a handwritten script, and I have to use iptables to block the access. I wrote the following rules:
iptables -A INPUT -p tcp -m multiport --dports 80,443 -s <valid IP 1> -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports 80,443 -s <valid IP 2> -j ACCEPT
...
iptables -A INPUT -p tcp -m multiport --dports 80,443 -s <valid IP n> -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports 80,443 -j DROP
It works. But when a new user is added through web interface, Apache launches a script as a non-root user. And I have to run iptables as root.
I can't set suid bit for a program, written in a scripting language, so I created a C program updater.c:
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int result = system("iptables -L");
printf("\nresult=%i", result);
return 0;
}
Then I compiled it:
# gcc -o updater ./updater.c
# chmod +s ./updater
When I run it as a non-priviledged user in shell it works correctly: prints all the iptables rules.
When I run it from the web, calling the program inside a shell script, it doesn't print anything. Despite the fact, that when I tried to create a file inside this C program, it was created with owner=root. system("ls -l"); also works - it prints the directory listing.
How can I manipulate iptables rules from the web script?
When you call system("iptables -L"); you may or may not be able to find iptables, depending on your PATH environment variable. You should prepend the path to where the binary is so that you know it will be found:
int result = system("/sbin/iptables -L");
As per impala documentation, you start impala shell using this command
$ impala-shell -i localhost --quiet
http://www.cloudera.com/documentation/enterprise/latest/topics/impala_tutorial.html#tut_beginner
Any idea what -i does? and why we needed?
Ok,
I think I found the answer.
By default impala-shell connect to localhost. So by only doing
$ impala-shell
This is going to go to the default impala host, port 21000
[localhost:21000] >
In case you are you want to manage impala in a cluster or a remote server you should specify a host by using the operator -i
such as impala-shell -i host.yourdomain.com
[host.yourdomain.com:21000] >
Or to a different port
such as impala-shell -i host.yourdomain.com:26000
[host.yourdomain.com:26000] >