本文共 1533 字,大约阅读时间需要 5 分钟。
首先在gcp创建实例
$ sudo passwd ${whoami} // 下面以 user 代替 ${whoami}# 输入新密码
$ sudo passwd root# 输入新密码
$ cd ~/.ssh$ ssh-keygen -f myKey或者$ ssh-keygen -t rsa -f ~/.ssh/my-ssh-key -C [USERNAME]Generating public/private rsa key pair.Enter passphrase (empty for no passphrase): ( 按enter键即可)Enter same passphrase again: ( 按enter键即可)Your identification has been saved in myKey.Your public key has been saved in myKey.pub.The key fingerprint is:SHA256:EW7ow1aaaaaf8mNvk user@computer-name.localThe key's randomart image is:+---[RSA 2048]----+|=.o+= o . ||o+.o+= + . ||o.o..oo * ||..o+ +o+ o ||.oo+ =+S o || o. * o. = o || ..o = . = ||. o.. . E || . .o. |+----[SHA256]-----+# 此时会生成 公钥 myKey.pub 和 私钥 myKey
$ cat myKey.pubssh-rsa AAAAaaaaaaaeglRVJzAhNq+W中间部分省略。。。dKx8sJ0Rw4aaaaaa845UVp1 user@computer-name.local# 把这长长的一段复制下来,把其中的 user@computer-name.local 改为你在浏览器 SSH 登入之后的当前用户名 ${whoami}
$ ssh -i myKey user@ip$ ssh-rsa [KEY_VALUE] [USERNAME]Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.11.2-041102-generic x86_64)
$ ssh user@ipPermission denied (publickey).# 之所以会出现这种情况,因为谷歌默认把密码验证登录关了,需要自行打开$ sudo vi /etc/ssh/sshd_configPasswordAuthentication yes :wq!
$ sudo service sshd restart
$ ssh user@ipuser@IP's password: (输入实例用户的密码)Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.11.2-041102-generic x86_64)
转载地址:http://mznax.baihongyu.com/