通过ssh连接而无需访问主文件夹

时间:2016-04-27 00:12:39

标签: amazon-web-services ssh amazon-ec2

我在Amazon EC2上安装了一个tomcat,并且我试图在/ home / ec2-user /文件夹中的文件夹中写入。 但我没有得到,因为tomcat用户有权访问该文件夹。

我尝试更改tomcat用户的所有者,但都没有。 我想也许文件夹/ home / ec2-user /是问题然后更改到该文件夹​​权限...但是没有用。

在互联网上搜索我找到了setenforce 0命令,但它没有用。

然后我关闭会话,当我再次尝试登录时收到以下消息

ssh -i "Amazon-Tomcat.pem" ec2-user@ec2-52-39-23-66.us-west-2.compute.amazonaws.com
Permission denied (publickey).

我想也许是因为我无法访问/ home / ec2-user /然后尝试root但我得到了

ssh -i "Amazon-Tomcat.pem" root@ec2-52-39-23-66.us-west-2.compute.amazonaws.com
Please login as the user "ec2-user" rather than the user "root".

Connection to ec2-52-39-23-66.us-west-2.compute.amazonaws.com closed.

如果我在连接命令中使用-v,则收到以下消息

ssh -i "Amazon-Tomcat.pem" ec2-user@ec2-52-39-23-66.us-west-2.compute.amazonaws.com -v
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ec2-52-39-23-66.us-west-2.compute.amazonaws.com [52.39.23.66] port 22.
debug1: Connection established.
debug1: identity file Amazon-Tomcat.pem type -1
debug1: identity file Amazon-Tomcat.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 21:76:3c:72:dd:68:14:c5:83:a6:09:9a:80:26:74:bc
debug1: Host 'ec2-52-39-23-66.us-west-2.compute.amazonaws.com' is known and matches the ECDSA host key.
debug1: Found key in /home/rodrigo/.ssh/known_hosts:7
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: OpenShift-Key
debug1: Authentications that can continue: publickey
debug1: Trying private key: Amazon-Tomcat.pem
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

非常感谢您的任何建议,原谅我的愚蠢

2 个答案:

答案 0 :(得分:1)

您的.ssh密钥公钥的权限过于宽松,这意味着ssh登录过程无法正常工作

要解决此问题,请参阅此问题的最高得分答案Change key pair for ec2 instance

基本上你必须将现在已损坏的ec2的磁盘安装到新的ec2上并修复它

要解决您的原始问题(tomcat写入文件夹),请提供"其他x"访问您的/ home / ec2-user主文件夹顶级

chmod o+x /home/ec2-user

和"所有"访问您的"文件夹"

chmod 777 /home/ec2-user/folder

保持.ssh目录和其他目录不变

下次测试ssh在您注销之前仍然有效!

答案 1 :(得分:1)

如果您使用的是Mac或Linux / unix风味机,请再次运行ssh命令,然后执行tail -f /var/log/auth.log。最后几行将给出确切的错误消息。尝试将keypair文件的权限更改为600(运行chmod 600 Amazon-Tomcat.pem),然后再次尝试ssh。