LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cannot ssh guest OS from host (https://www.linuxquestions.org/questions/linux-newbie-8/cannot-ssh-guest-os-from-host-905166/)

konsolelover 09-27-2011 12:18 AM

Cannot ssh guest OS from host
 
Hello everyone,
So I'm a Linux newbie. I'm trying to learn ssh ,ftp, telnet and other stuffs after introducing myself to some basic commands.But my problem is that i have only one laptop , so i decided to give a go to VirtualBox .Ok lets cut this crap and head to the main problem...
Host = Ubuntu 11.04
Guest = Arch 2.6.33
VM= VirtualBox 4.0.10
I have installed openssh in both machines.I followed the this link
http://www.wiredrevolution.com/virtu...-and-guest-vms
So now this is what i can do,
1- I can ping and ssh from guest to host :)
2- I can ping guest from host but cannot ssh.(i need to mention that i used
Quote:

ifconfig eth1 192.168.56.2 netmask 255.255.255.0
command in guest ) And here is the error when i try to ssh guest OS
Quote:

OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.56.2 [192.168.56.2] port 22.
debug1: connect to address 192.168.56.2 port 22: Connection refused
ssh: connect to host 192.168.56.2 port 22: Connection refused
3- Checked firewall in Ubuntu 11.04 it says it's inactive and i assume there's no default firewall in Arch(correct me if i am wrong)
Do i need to change something in hosts.deny or hosts.allow in guest or host os(I think it's related to something tcp wrappers but i don't have any idea). I don't know what to do :|
Any help will be appreciated TIA

indeliblestamp 09-27-2011 01:01 AM

Is an ssh server running on the guest? do an 'ssh localhost' on it to see if that works first.

konsolelover 09-27-2011 01:34 AM

oops!
Quote:

ssh: connect to host localhost port 22: connection refused
I thought checking sshd was enough, my bad...
How can i process now (Ok Gonna google it)
Thanks for your reply

indeliblestamp 09-27-2011 02:08 AM

Arch has an excellent wiki. Here is their SSH page: https://wiki.archlinux.org/index.php/Secure_Shell (you'll need just section 1 to get started).

konsolelover 09-27-2011 02:42 AM

I'm clueless
Quote:

rc.d start sshd
bash : rc.d : command not found

Chenchu 09-27-2011 02:53 AM

Are you running the command as root user?

MrCode 09-27-2011 03:03 AM

(removed; I'm stupid)

EDIT: Actually, maybe I can still help (:p): try just directly invoking the daemon script with /etc/rc.d/sshd start. rc.d, AFAIK, is mostly just a proxy/enhancement to that functionality.

…and yes, make sure you're root as well. ;)

EDIT++: pgrep sshd to see if it's already running.

konsolelover 09-27-2011 03:53 AM

Quote:

Are you running the command as root user?
sudo rc.d start sshd
Quote:

sudo : rc.d : command not found
Also tried by switching to root user....

konsolelover 09-27-2011 03:58 AM

Quote:

Originally Posted by MrCode (Post 4483302)
(removed; I'm stupid)

EDIT: Actually, maybe I can still help (:p): try just directly invoking the daemon script with /etc/rc.d/sshd start. rc.d, AFAIK, is mostly just a proxy/enhancement to that functionality.

…and yes, make sure you're root as well. ;)

EDIT++: pgrep sshd to see if it's already running.

/etc/rc.d/sshd start worked :)
but when i had tried
Quote:

ps aux| grep sshd
it showed that it's running and
Quote:

pgrep sshd
didn't. Why??
BTW thanks for your response :)
EDIT: So now i can access my guest OS using eth1 interface but when i try to access guest OS using ip of eth0 interface neither i can ping nor ssh.It means that it won't be accessible from internet (other than host OS and other guests). :confused:

MrCode 09-27-2011 05:01 AM

Quote:

EDIT: So now i can access my guest OS using eth1 interface but when i try to access guest OS using ip of eth0 interface neither i can ping nor ssh.It means that it won't be accessible from internet (other than host OS and other guests).
You should be able to work around this by allowing internet access from the guest through your host's network interface.

Here's what I do if I want a virtual machine to be accessible through SSH while still having internet access:


1. Set up iptables/IP forwarding on the host:

Code:

iptables -t nat -A POSTROUTING -o <host network interface> -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

(don't forget to (re)start iptables ;))

2. Set the default gateway/DNS nameservers on the guest: point the gateway to the IP of the host virtual network interface (typically vboxnet0), and set the DNS servers to be identical to those on the host. I usually stick these lines in /etc/rc.local (or whatever the equivalent init script is in whatever distro/OS it is that I'm messing with :p):

Code:

echo "nameserver <ISP DNS server IP, or maybe router IP>" > /etc/resolv.conf
route add default gw <IP of virtual host interface>

I don't guarantee that this exact setup will work for you, but it works for me, so… :scratch: :-\

EDIT: If you need more details on this, the Arch Wiki delivers. ;) Most of the information there should apply just as well to a "share" between a host and a VM as it does a network between two real machines.

konsolelover 09-27-2011 08:13 AM

Hmmm gotta learn iptables next. Thanks for your replies and thread gets the solved prefix. ;-)


All times are GMT -5. The time now is 12:58 AM.