我正在使用gcp虚拟机实例N1标准8V-30GB和N1标准4V-15GB
我从最近1个月开始面临这个问题。
拒绝公共访问权限是我尝试从云外壳访问时看到的消息之一
我之前运行过command chmod 777 <home directory>
。
答案 0 :(得分:1)
我尝试重现您的步骤,并能够解决此问题。
请在下面查看我的步骤
gcloud compute instances create instance-1 --zone=europe-west3-a --machine-type=e2-medium --image=ubuntu-1804-bionic-v20200701 --image-project=ubuntu-os-cloud
gcloud compute instances create instance-2 --zone=europe-west3-a --machine-type=e2-medium --image=ubuntu-1804-bionic-v20200701 --image-project=ubuntu-os-cloud
instance-1
上我的主目录上的instance-1:~$ chmod -R 777 ~
instance-1:~$ ls -la
...
drwxrwxrwx 2 username username 4096 Jul 15 07:50 .ssh
instance-1
启动磁盘的gcloud compute disks snapshot instance-1 --snapshot-names instance-1-snapshot --zone=europe-west3-a
gcloud compute disks create instance-1-snapshot-disk --zone=europe-west3-a --source-snapshot=instance-1-snapshot
instance-1-snapshot-disk
的磁盘instance-2
:instance-2:~$ ls -l /dev/ | grep sd
brw-rw---- 1 root disk 8, 0 Jul 15 07:39 sda
brw-rw---- 1 root disk 8, 1 Jul 15 07:39 sda1
brw-rw---- 1 root disk 8, 14 Jul 15 07:39 sda14
brw-rw---- 1 root disk 8, 15 Jul 15 07:39 sda15
instance-2:~$ mount | grep sda
/dev/sda1 on / type ext4 (rw,relatime)
/dev/sda15 on /boot/efi type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
然后
gcloud compute instances attach-disk instance-2 --disk=instance-1-snapshot-disk --zone=europe-west3-a
之后
instance-2:~$ ls -l /dev/ | grep sd
brw-rw---- 1 root disk 8, 0 Jul 15 07:39 sda
brw-rw---- 1 root disk 8, 1 Jul 15 07:39 sda1
brw-rw---- 1 root disk 8, 14 Jul 15 07:39 sda14
brw-rw---- 1 root disk 8, 15 Jul 15 07:39 sda15
brw-rw---- 1 root disk 8, 16 Jul 15 08:04 sdb
brw-rw---- 1 root disk 8, 17 Jul 15 08:04 sdb1
brw-rw---- 1 root disk 8, 30 Jul 15 08:04 sdb14
brw-rw---- 1 root disk 8, 31 Jul 15 08:04 sdb15
instance-2:~$ sudo mkdir /mnt/instance-1-snapshot-disk
instance-2:~$ sudo mount /dev/sdb1 /mnt/instance-1-snapshot-disk
instance-2:~$ ls -la /mnt/instance-1-snapshot-disk
total 104
drwxr-xr-x 23 root root 4096 Jul 15 07:56 .
drwxr-xr-x 3 root root 4096 Jul 15 08:05 ..
drwxr-xr-x 2 root root 4096 Jul 1 19:14 bin
drwxr-xr-x 4 root root 4096 Jul 1 19:19 boot
drwxr-xr-x 4 root root 4096 Jul 1 19:11 dev
drwxr-xr-x 93 root root 4096 Jul 15 07:55 etc
drwxr-xr-x 4 root root 4096 Jul 15 07:50 home
lrwxrwxrwx 1 root root 30 Jul 1 19:18 initrd.img -> boot/initrd.img-5.3.0-1030-gcp
lrwxrwxrwx 1 root root 30 Jul 1 19:18 initrd.img.old -> boot/initrd.img-5.3.0-1030-gcp
drwxr-xr-x 22 root root 4096 Jul 1 19:17 lib
drwxr-xr-x 2 root root 4096 Jul 1 19:01 lib64
drwx------ 2 root root 16384 Jul 1 19:13 lost+found
drwxr-xr-x 2 root root 4096 Jul 1 19:01 media
drwxr-xr-x 2 root root 4096 Jul 1 19:01 mnt
drwxr-xr-x 2 root root 4096 Jul 1 19:01 opt
drwxr-xr-x 2 root root 4096 Apr 24 2018 proc
drwx------ 3 root root 4096 Jul 15 07:36 root
drwxr-xr-x 4 root root 4096 Jul 1 19:19 run
drwxr-xr-x 2 root root 4096 Jul 1 19:17 sbin
drwxr-xr-x 6 root root 4096 Jul 15 07:36 snap
drwxr-xr-x 2 root root 4096 Jul 1 19:01 srv
drwxr-xr-x 2 root root 4096 Apr 24 2018 sys
drwxrwxrwt 7 root root 4096 Jul 15 07:56 tmp
drwxr-xr-x 10 root root 4096 Jul 1 19:01 usr
drwxr-xr-x 13 root root 4096 Jul 1 19:12 var
lrwxrwxrwx 1 root root 27 Jul 1 19:18 vmlinuz -> boot/vmlinuz-5.3.0-1030-gcp
lrwxrwxrwx 1 root root 27 Jul 1 19:18 vmlinuz.old -> boot/vmlinuz-5.3.0-1030-gcp
.ssh
目录:700 drwx------
.pub
文件):644 -rw-r--r--
id_rsa
):600 -rw-------
drwxr-xr-x
instance-2:~$ chmod -R 755 /mnt/instance-1-snapshot-disk/home/username/
instance-2:~$ chmod -R 700 /mnt/instance-1-snapshot-disk/home/username/.ssh/
instance-2:~$ chmod 644 /mnt/instance-1-snapshot-disk/home/username/.ssh/authorized_keys
完成后卸载磁盘:
instance-2:~$ sudo umount /mnt/instance-1-snapshot-disk/
instance-1-snapshot-disk
中的instance-2
:gcloud compute instances detach-disk instance-2 --disk=instance-1-snapshot-disk --zone=europe-west3-a
gcloud compute instances create instance-3 --zone=europe-west3-a --machine-type=e2-medium --disk=name=instance-1-snapshot-disk
instance-1
上检查SSH连接。此外,请查看文档Troubleshooting SSH部分Inspect the VM instance without shutting it down,以了解更多详细信息。
答案 1 :(得分:0)
我从所有者的帐户尝试访问实例1,但所有者也无法连接到实例1。
项目所有者在ssh窗口中看到了此弹出窗口 [1]:https://i.stack.imgur.com/y2fzC.jpg
我观察到,在新创建的实例中,如果我添加了一些文件,例如git clone repo,然后重新启动它,则可以再次连接SSH。