Enable Linux SSH (CentOS) in VirtualBox)

Source: Internet
Author: User

Enable Linux SSH (CentOS) in VirtualBox)

The first time I used SSH to connect to Linux installed on VirtualBox, I plan to buy a cloud space for use, so I should first use a CentOS trainer. Because it is on a virtual machine, it is a small discount for connecting via SSH. I would like to record it here. I chose CentOS6.4, which mainly includes the following steps:

1. Switch the network mode of the VM.
2. Set the sshd service to start automatically.
3. Start the sshd service.
4. Putty connection.
5. problems encountered during the process.

Because SSH and the virtual machine share a single machine, after CentOS is installed, you cannot determine what the IP address to connect. Because VirtualBox is NAT by default (Network Address Translation, therefore, although you can see the IP address of the virtual network card through ipconfig on the host machine, it cannot be connected to the Virtual Machine (as if you want to modify the forwarding rule of VirtualBox, this will be tried later ). In the end, the network Adapter address is directly sent to Centos by modifying the network connection mode Bridge Adapter.
Modify the procedure: Shut down the Virtual Machine. On the Management page, select Virtual Machine --> Settings --> network:


After setting, you can view the current IP address on the CentOS terminal. ifconfig:


At this point, Part 1 is closed, and the sshd service is set to self-start, so that you do not have to run to the virtual machine to start once after each boot.
Run the command: chkconfig sshd on to set it to boot
Run the command: chkconfig -- list | grep sshd to view the setting result. Note that you need the root permission to set it here. As follows:

Assume that the List contains 0 ~ 6. It should represent the operating mode of Linux.

Start sshd in the next 3. If the default port is 22, run the command: service sshd start.

Then there is 4 using the ssh tool. Here is the putty connection. In CentOS, the iptables policy is ACCEPT by default, so you do not need to set it. If it is another system, firewall access may be involved. In section 5.

5. Problems:
The biggest problem encountered should be that the IP address in the virtual machine is not accurate, and a lot of attempts and google were made, and the netfilter component (iptables) was stopped at one time ).
Secondly, although the iptables rule in CentOS is ACCEPT by default, you can select DROP in INPUT and OUTPUT for the sake of security in actual scenarios. In this case, you need to add a command to develop port 22:
Iptables-a input-p tcp-m tcp-sport 22-j ACCEPT
Iptables-a output-p tcp-m tcp-dport 22-j ACCEPT

 

--------------------------------------------------------
Add a postscript:
After trying it out, you don't need to switch the network mode. You can simply use Nat. Find an introduction to the network from the help of VirtualBox. The NAT mode is similar to the physical router in the home, but this time the router is the VirtualBox routing engine, which isolates the virtual machine from the outside, you only need to configure port forwarding to connect to the virtual machine port. The final result is that all messages sent to the port specified by the virtual network card IP address of VirtualBox are forwarded to the corresponding port, here 22 is required. The settings are as follows:
1. Disable the VM and set the network to NAT and add port forwarding rules:

2. connect directly to the corresponding port of the virtualBox virtual Nic. You can view the current ip address of my virtualBox through ipconfig of the host machine as 192.168.56.1 @ 1022:

3. Close the job. The connection is normal.

How to Improve the SSH login authentication speed of Ubuntu

Enable the SSH service to allow Android phones to remotely access Ubuntu 14.04

How to add dual authentication for SSH in Linux

Configure the SFTP environment for non-SSH users in Linux

Configure and manage the SSH service on Linux

Basic SSH tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.