how do you translate this ssh command into a ssh_config file? - linux

I am trying to translate this ssh command into my ssh_config. What is the equivalant of -L in the ssh_config? I thought it was localForward but from the restuls i am getting it does not look that way.
SSH command
sudo ssh -i ~/.ssh/mySSHkey -L 81:<IP1>:81 -L 9200:<IP1>:9200 user#myhost.domain.com
ssh_config entry
Host logstash
Hostname <IP1>
Port 81
# ForwardX11 yes
LocalForward 81 <IP1>:81
LocalForward 9200 <IP1>:9200
User username
IdentityFile ~/.ssh/mySSHkey
ServerAliveInterval 30
ServerAliveCountMax 120
# LogLevel DEBUG3

Host tunnel
HostName database.example.com
IdentityFile ~/.ssh/john.example.key
LocalForward 9906 127.0.0.1:3306
User john
Equivalent of:
ssh -f -N -L 9906:127.0.0.1:3306 john#database.example.com
With the new config in place you can run:
ssh -f -N tunnel
Source: http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/

Related

kex_exchange_identification: Connection closed by remote host with ~/.ssh/config file

I have a bastion host where I have configured the ~/.ssh/config file as follows:
Host stage-bastion
ProxyCommand ssh -q stage-bastion nc -q0 <capped-ip> 22
Hostname <capped-ip>
User stage
IdentityFile /home/abc/Documents/key
Port 1984
ServerAliveInterval 15
ServerAliveCountMax 3
And I try to log in as follows:
ssh stage-bastion
and I get the error:
kex_exchange_identification: Connection closed by remote host
I even did a eval "$(ssh-agent -s)" but not luck.
Then I tried normally as below:
ssh -i /home/abc/Documents/key stage#<capped-ip>
Voila it worked and I was able to ssh.
Can someone help me why my ~/.ssh/config is not working and giving the above error?

ssh tunnel from azure bastion hosts

Is it possible to do ssh tunneling (SSH port forwarding) from azure bastion host?
Like we do normally from a jump box:
ssh -i path/to/private_key -L 127.0.0.1:FORWARD_PORT:VM_IP:APPLICATION_PORT user#jumphost.net
ssh -i path/to/private_key -L 127.0.0.1:8080:10.0.0.1:8080 user#jumphost.net
Do you really need port fowarding? Your use case can perfectly use TCP forwarding like so, with the following SSH config.
Host JumpHost1
Hostname jumphost1.net
User user_jh1
Host JumpHost2
Hostname jumphost2.net
User user_jh2
ProxyCommand ssh -W %h:%p JumpHost1
Host AppBox
Hostname appbox_behind_firewall.net
User app_user
ProxyCommand ssh -W %h:%p JumpHost2
Then you can easily do ssh AppBox without issue. You'll need to have your local public key authenticated to each jumphost and the appbox. Which you should be able to easily do with ssh-copy-id if you are doing this with OpenSSH

ssh inside ssh with multiples commands

When I try more than one command to remotely execute commands through ssh inside other ssh, I get weird result.
From man ssh:
-t
Force pseudo-terminal allocation. This can be used to execute
arbitrary screen-based programs on a remote machine, which can be very
useful, e.g. when implementing menu services. Multiple -t options
force tty allocation, even if ssh has no local tty.
If I do
ssh -t root#host1 ssh root#host2 "cat /etc/hostname && cat /etc/hostname"
or
ssh -t root#host1 ssh -t root#host2 "cat /etc/hostname && cat /etc/hostname"
in both cases I get
host1
Connection to host1 closed.
host2
Connection to host2 closed.
I want this result:
host1
host1
Connection to host1 closed.
Connection to host2 closed.
I want to run all commands in same server using ssh inside ssh.
If I use only one ssh, it works:
ssh -t root#host1 "cat /etc/hostname && cat /etc/hostname"
host1
host1
Connection to host1 closed.
I get it work, but I can not explain what is happening.
ssh -t root#host1 "ssh -t root#host2 \"cat /etc/hostname ; cat /etc/hostname\""
host1
host1
Connection to host1 closed.
Connection to host2 closed.
Try:
That's not how -t works.
For your option try:
ssh root#host1 .....; ssh root#host2 ....
Otherwise, use PSSH that will do the uptime command on both servers at same time:
pssh -h hostfile -i uptime

ssh failed when installing hadoop:connect to host master port 22: connection refused

I want to install hadoop cluster, the hostname of my computer is modified Master. I configure the ssh login without password, but I can only use ssh localhost successfully, when it comes to ssh Master, it shows ssh:connect to host master port 22: connection refused. I don't know why
/etc/host
127.0.0.1 localhost
113.*.*.2 Master
113.*.*.31 Slave1
cd ~/.ssh
rm ./id_rsa
ssh-keygen -t rsa
cat ./id_rsa.pub >> ./authorized_keys
ssh Master
Do this :
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root#master
ssh-copy-id -i ~/.ssh/id_rsa.pub root#slave1
chmod 0600 ~/.ssh/authorized_keys

SSH commands from script to remote server not working

Greeting All,
I have following query and would appreciate any help on this.Thanks.
Scenario :
My local server (server-A) is connected to one remote server (server-B).Server-B is connected to 10 other remote servers (Server-C...Server-L).
Server-A is not directly connected to (Server-C...Server-L) ,its only connected through Server-B.
I have managed to do SSH key pairing between:
Server-A <----> Server-B
Server-B <----> Server-C....Server-L
So now I can login into Server-C from Server-A using below command:
From Server-A :
ssh user-B#(IP-Server-B) -t ssh user-c#(IP-Server-C)
ssh -t user-B#(IP-Server-B) -t scp -oStrictHostKeyChecking=no test.file user-c#(IP-Server-C):/home/user-C
Here is my actual script: (Running from Server-A)
while read line
do
scp -oStrictHostKeyChecking=no test.file user-B#(IP-Server-B):/home/user-B
ssh -t user-B#(IP-Server-B) -t scp -oStrictHostKeyChecking=no test.file mtc#$line:/home/mtc
ssh -t user-B#(IP-Server-B) -t ssh -t -tqn user-c#$line sh /home/user-c/test.file
ssh -t user-B#(IP-Server-B) -t scp user-c#$line:/home/user-c/junk.txt /home/user-B
ssh -t user-B#(IP-Server-B) -t ssh user-c#$line rm -rf /home/user-c/junk.txt
scp user-B#(IP-Server-B):/home/user-B/junk.txt .
mv junk.txt junk.txt_$line
done < LabIpList
Here is the list of IP address of servers Server-c...Server-L.
cat LabIpList
1.2.3.4
2.3.4.5
3.4.5.6
4.5.6.7
5.6.7.8
6.7.8.9
7.8.9.10
....
.....
Query:
If I do above commands on command line then they work flawlessly, however If I put them on script then they fail. Because of two reasons :
tcgetattr: Inappropriate ioctl for device
pseudo-terminal will not be allocated
As the SSH-keys are recently exchanged , so user have to manually type yes to add them to know_hosts.
I believe you have already created passwordless login using ssh-keygen.Please use below options for ssh in the script
ssh -t -t -tq <IP>

Resources