首页 技术 正文
技术 2022年11月15日
0 收藏 377 点赞 3,790 浏览 1044 个字

例如:

$ ssh -i ~/ec2.pem ubuntu@12.34.56.78

首先确定你可以以密码的形式连接远程服务器,也可以创建一个非超级管理员用户,并增加 sudo 权限

$ sudo ssh root@12.34.56.78

生成 .pem 步骤如下:

1.客户端(本地主机 )生成验证没有密码密钥对

$ ssh-keygen -t rsa -b 2048 -v

执行上述命令首先会让你输入生成密钥的文件名:我这里输入的 myPemKey ,之后一路回车。

Generating public/private rsa key pair.
Enter file in which to save the key (/home/anonymouse/.ssh/id_rsa): myPemKey
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in hetzner.
Your public key has been saved in hetzner.pub.
The key fingerprint is:
bb:c6:9c:ee:6b:c0:67:58:b2:bb:4b:44:72:d3:cc:a5 localhost@localhost
The key's randomart image is:

在执行命令的当前目录下会生成一个myPemKey.pub、myPemKey 两个文件。

2. 把生成的 myPemKey.pub 通过本地命令推送到服务器端,使服务器自动添加认证这个证书

$ ssh-copy-id -i ~/myPemKey.pub root@12.34.56.78

输入你的 root 用户密码

3. 测试连接

$ sudo ssh -i ~/myPemKey root@12.34.56.78

或者把 myPemKey 重命名为 myPemKey.pem

$ sudo ssh -i ~/myPemKey.pem root@12.34.56.78

4. 禁用密码连接(注意:要保证 .pem 连接成功的状态下,禁用密码连接)

sudo vi /etc/ssh/sshd_config

找到这一行 #PasswordAuthentication yes

# Change to no to disable tunnelled clear text passwords
# PasswordAuthentication yes

取消前边的 # 注释,改为

PasswordAuthentication no

重启 ssh 服务

sudo service ssh restart
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919