SSH密钥身份验证在Tera Term中不起作用。

huangapple go评论64阅读模式
英文:

SSH key authentication not working in Tera Term

问题

我正在创建一个CDK部署,以自动化服务器的部署。到目前为止,这是我的代码:

// 创建SSH密钥对
let keyPair = new ec2.CfnKeyPair(this, "PublicEC2Key", {
  keyName: "public-ec2-key",
  tags: [new cdk.Tag("Name", `public-ec2-key`)],
});

// 创建安全组
const publicEC2SG = new ec2.SecurityGroup(this, `publicEC2SG`, {
  vpc: vpc,
  allowAllOutbound: true,
  description: `Public CLC instance Security Group`,
  securityGroupName: `clc-public-ec2-sg`,
});
publicEC2SG.addIngressRule(
  ec2.Peer.anyIpv4(),
  ec2.Port.tcp(22),
  "SSH from anywhere"
);      

// 在公共子网中启动EC2实例(以便通过SSH访问)
let ec2_public = new ec2.Instance(this, "PublicEC2", {
  vpc: vpc,
  vpcSubnets: {
    subnetType: ec2.SubnetType.PUBLIC,
  },
  instanceType: ec2.InstanceType.of(
    ec2.InstanceClass.T2,
    ec2.InstanceSize.MICRO
  ),
  role: roleEC2,
  machineImage: ec2.MachineImage.latestAmazonLinux2023(),
  instanceName: `clc-public-ec2`,
  keyName: keyPair.keyName,
  securityGroup: publicEC2SG,
});

在正确部署VPC和实例后,我可以在控制台上看到实例和密钥对。然后我转到Parameter store,从那里复制密钥并创建一个名为public-ec2-key.pem的新文件,在其中粘贴证书代码(从-----BEGIN RSA PRIVATE KEY-----到-----END RSA PRIVATE KEY-----包括在内)。

我更改文件的权限为:

chmod 400 public-ec2-key.pem

最后,我尝试使用Tera Term连接到EC2实例,并使用创建的.pem文件,但它返回身份验证错误

我可以通过SSH访问实例,但无法正确验证。我是否漏掉了一步?

谢谢,祝一切顺利!

更新:当我尝试直接使用Linux终端的ssh命令连接时,它可以正常工作:
ssh -i "public-ec2-key.pem" ec2-user@ec2-ip-address.compute-1.amazonaws.com

我需要在我的TeraTerm中配置什么吗?

英文:

I'm creating a CDK deployment to automate the deployment of a server. This is my code so far:

    let keyPair = new ec2.CfnKeyPair(this, "PublicEC2Key", {
      keyName: "public-ec2-key",
      tags: [new cdk.Tag("Name", `public-ec2-key`)],
    });

    // Create security group
    const publicEC2SG = new ec2.SecurityGroup(this, `publicEC2SG`, {
      vpc: vpc,
      allowAllOutbound: true,
      description: `Public CLC instance Security Group`,
      securityGroupName: `clc-public-ec2-sg`,
    });
    publicEC2SG.addIngressRule(
      ec2.Peer.anyIpv4(),
      ec2.Port.tcp(22),
      "SSH from anywhere"
    );      

    // Launch EC2 instance in the public subnet (to be able to access it via SSH)
      let ec2_public = new ec2.Instance(this, "PublicEC2", {
        vpc: vpc,
        vpcSubnets: {
          subnetType: ec2.SubnetType.PUBLIC,
        },
        instanceType: ec2.InstanceType.of(
          ec2.InstanceClass.T2,
          ec2.InstanceSize.MICRO
        ),
        role: roleEC2,
        machineImage: ec2.MachineImage.latestAmazonLinux2023(),
        instanceName: `clc-public-ec2`,
        keyName: keyPair.keyName,
        securityGroup: publicEC2SG,
      });

After correctly deploying the VPC and the instance I can see both the instance in the console as well as the key pair. I then go to the
Parameter store from where I copy the key and create a new file named public-ec2-key.pem where I paste the certificate code (from -----BEGIN RSA PRIVATE KEY----- to -----END RSA PRIVATE KEY----- included).

I change the permissions of the file to:

chmod 400 public-ec2-key.pem

Finally I try to connect to the EC2 instance using Tera Term and the .pem file created but it returns an authentication error.

The instance is accesible via SSH, but I cannot authenticate correctly. I'm I missing a step?

Thank you and best regards!

UPDATE: When I try connecting through ssh command using the linux terminal directly it works:
ssh -i "public-ec2-key.pem" ec2-user@ec2-ip-address.compute-1.amazonaws.com

It's there anything I need to configure in my TeraTerm?

答案1

得分: 1

我怀疑你正在尝试使用 rsa-sha2-256 或 rsa-sha2-512。这不受当前版本的 Tera Term 支持。请尝试 Tera Term 5 RC 5.0 beta1,它支持这些功能。

英文:

I suspect you are trying to use rsa-sha2-256 or rsa-sha2-512. This isn't supported by the current version of Tera Term. Try Tera Term 5 RC 5.0 beta1, which does.

huangapple
  • 本文由 发表于 2023年6月15日 21:59:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483253.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定