limits.conf中的条目错误,无法通过ssh连接到主机
我们有VirtualBox(使用vagrant)env,错误地在/etc/security/limits.conf中创建了一个条目,[没有打开一个根shell:(],现在我无法使用ssh(连接会立即断开)。 以前我们有一个这样的场景(限制由其他人完成),能够使用vboxmanage guestcontrol copyto CLI进行修复,并且能够覆盖limits.conf,然后允许ssh,这次vboxmanage CLI也挂起limits.conf中的条目错误,无法通过ssh连接到主机,ssh,vagrant,virtualbox,Ssh,Vagrant,Virtualbox,我们有VirtualBox(使用vagrant)env,错误地在/etc/security/limits.conf中创建了一个条目,[没有打开一个根shell:(],现在我无法使用ssh(连接会立即断开)。 以前我们有一个这样的场景(限制由其他人完成),能够使用vboxmanage guestcontrol copyto CLI进行修复,并且能够覆盖limits.conf,然后允许ssh,这次vboxmanage CLI也挂起 尝试在GUI中打开VM,然后转到控制台并尝试了几个选项,但无法进入单
尝试在GUI中打开VM,然后转到控制台并尝试了几个选项,但无法进入单用户模式。由于您已经尝试了vbox cli命令,并且命令挂起,这意味着即使virtualbox也无法访问系统或打开shell 在这种情况下,你必须启动一个ubuntu虚拟机,并使用qemu nbd模块来修复这个问题 通过执行以下步骤,在同一主机上使用hashicorp的bionic64创建一个非常简单的ubuntu虚拟机
mkdir bionic
cd bionic
vagrant box add hashicorp/bionic64
vagrant init
Open the Vagrantfile and change the config.vm.box = "base" to config.vm.box = "hashicorp/bionic64"
Also mount the folder in the host where the .vdi file for the VM is located by adding the following to the Vagrant file by adding the following line(replace the file path with the correct one corresponding to your system. Here /nbd2 will be created on the ubuntu machine and will contain the files including the .vdi file.
config.vm.synced_folder "/home/topcat/VirtualBox\ VMs/your_vm", "/nbd2"
Now do vagrant up
Once the machine boots up
vagrant ssh #to ssh as vagrant
sudo su #to become root
apt-get update #This will refresh the apt cache
apt-get install qemu
modprobe nbd (to check if the module is loaded successfully. Will exit without any output if it is installed)
qemu-nbd -c /dev/nbd1 "/nbd2/box-disk001.vdi" - (Here change the path to whatever you gave in the config.vm.synced_folder property)
mkdir -p /mnt/vdi-boot
mount /dev/nbd1p1 /mnt/vdi-boot
cd /mnt/vdi-boot/etc/security (This folder will have all the files as it were in your VM)
touch limits.conf (if the file is already there, delete it)
chmod 644 limits.conf
chown root:root limits.conf
open the /mnt/vdi-boot/etc/security/nsswitch.conf file and check if the following three lines are present
passwd: files
shadow: files
group: files
umount /mnt/vdi-boot (unmounts the mounted path)
qemu-nbd -d /dev/nbd1 (disconnects from qemu-nbd)
Exit the VM and start the VM
Open another shell and try to ssh. It should go through fine this time.
感谢Sharath,您提供的解决方案起了作用,我能够在不丢失数据的情况下恢复VM,现在SSH也可以工作了