I cannot set an SSH password and hostname for Vagrant - ssh

I have a Vagrant file looks like the one below.
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.ssh.host = "0.0.0.0"
config.ssh.password = "foo"
end
I want to access to my box via an SSH tool. When I try to connect it with a command like ssh vagrant#0.0.0.0:22, I encounter with an error that says ssh: Could not resolve hostname 0.0.0.0:22: nodename nor servname provided, or not known
.
According to Vagrant documents, it is possible to set a hostname and password by setting host and password properties of ssh object of the config.
I am sure that the current Vagrant box is up and running. I can even access apache via port 80 if I set forwarded_port attribute.
config.vm.network "forwarded_port", guest: 80, host: 80, host_ip: "127.0.0.1"

That's not valid ssh command line syntax. Use the -p command line parameter to specify the port. For example:
This works: ssh -p 2222 -i /path/to/identity/file vagrant#localhost
This does not: ssh -i /path/to/identity/file vagrant#localhost:2222
Note: port 22 is the default port for ssh, if you're attempting to connect to port 22 then you don't have to specify the port.

Related

Merge ssh config

Is there a way to merge the ssh config file into one session?
Such as
$ vim ~/.ssh/config
Host sshtest1
HostName 192.168.1.11
User ec2-user
Host ssttest2
HostName 192.168.1.12
User ec2-user
into
Host sshtest?
HostName 192.168.1.1?
User ec2-user
I did a try, but got this error:
ssh: Could not resolve hostname 192.168.1.1?: nodename nor servname
provided, or not known
Suppose I have 9 nodes. I don't want to repeat that sessions.
You can merge common line like this:
Host sshtest1
HostName 192.168.1.11
Host ssttest2
HostName 192.168.1.12
Host *
User ec2-user

Setup ssh_config with proxies when AllowTCPForwarding is not allowed

How can you write the following setup in an ssh config.
### The Bastion Host
Host bastion-host-nickname
HostName bastion-hostname
### The Remote Host
Host remote-host-nickname
HostName remote-hostname
ProxyJump bastion-host-nickname
### The Remote Host VM
Host remote-host-vm-nickname
Hostname remote-vm-hostname
????
I have a bastian sever through which my remote-host can be reached via ssh. This connection is working as expected. On my remote-host there are a few virtual machines (the remote host vm) that can also be reached via ssh.
AllowTCPForwarding is disabled in the sshd_config of the remote-host. Therefore neither an SSH tunnel nor a ProxyCommand can be used. With both you get the error message "... administratively prohibited". The sshd_config should stay that way.
My preferred approach is that I connect to the remote-host and execute the following command:
[#remote-host]
"ssh -t -i keyfile user#remote-vm-hostname \" whoami \ ""
How can I describe this ssh command in my ssh_config?
Especially so that this ssh command can only be executed on my remote host.

SSH port forwarding: bind: Address already in use

I have a remote server which I want to ssh it and forward my local port into it.
My application is hosting port 443 on my local machine. I'm connecting to the server with gcloud. This is the command:
gcloud compute --project "**^" ssh --zone "***" "***"
The target is to allow other to communicate, on port 9000, with the server and this traffic will redirected into my local machine, on port 443. On other words, accessing server on port 9000 is equal to access my computer on port 443.
So I do ssh port forwarding
gcloud compute --project "**^" ssh --zone "***" "***" -- -L 443:127.0.0.1:9000 -N
and get back this error:
bind: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 443
Could not request local forwarding.
What I'm doing wrong?
The correct option is -R
... -R 9000:localhost:443
linux
if you have no other ssh connection you can fix it with :
killall ssh

Ansible: Cannot login to local Vagrant server

I have two Vagrant instances running having different IP:
192.168.33.17 [Ansible installed here]
192.168.33.19 [Another server where I am trying to connect]
My Ansible hosts file is in /etc/ansible/hosts and it looks like:
[example]
192.168.33.19:2222
I can easily connect via SSH to the second server with command:
ssh vagrant#192.168.33.19
without password.
But running the Ansible command yields error:
[root#centos72x64 vagrant]# ansible example -m ping -u vagrant
192.168.33.19 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}
How I can solve this error?
My Ansible hosts file is in /etc/ansible/hosts and it looks like
[example]
192.168.33.19:2222
You don't put port number in the Ansible inventory file this way. To learn how to do it, confer the docs.
But you also mentioned:
I can easily connect via ssh to the second server with command
ssh vagrant#192.168.33.19
So you don't use port 2222 at all.

Can't `ssh` onto Private Network

Given the following Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos_64"
config.vm.host_name = 'web'
config.vm.network "private_network", ip: "192.168.50.4"
end
Why can't I ssh onto the guest from the host?
$ ssh vagrant#web -p 22
ssh: connect to host web port 22: Connection timed out
But using vagrant ssh works:
$ vagrant ssh
Last login: Tue Mar 4 21:29:24 2014 from 10.0.2.2
[vagrant#web ~]$
As expected, I can ping the IP Address from the guest. But I can't ping from the host.
I'm confused as to why it's happening since my setup does not look different from this configuration.
First, vagrant ssh uses the forwarded port and not the private network address. You can get the configuration with vagrant ssh-config.
Is the name "web" really resolving to the specified IP? Can you ping/connect using the IP instead of the name? If not, verify that you don't have other VMs or external networks with the same address. Also some VPN products mess up the routing.
I managed to change the ssh address with
config.ssh.host = '192.168.0.13'
config.ssh.port = '22'`
as mentioned in https://superuser.com/questions/920536/how-to-change-the-ssh-host-in-vagrantfile/921728#921728
Just because the guest host has a defined hostname does not mean that the host machine will resolve its ip.
You should be able to ssh into the machine by doing:
ssh vagrant#192.168.50.4 <==== vagrant is the default password,
but you can avoid typing it alway by doing:
ssh-copy-id vagrant#192.168.50.4
here is my configuration and it's working for me
config.vm.box = "ubuntu/xenial64"
config.vm.network "private_network", ip: "192.168.88.88"
config.ssh.host = "192.168.88.88"