简体   繁体   English

AWS EC2和rvm ssh

[英]AWS EC2 and rvm ssh

I have created user for my AWS ec2 VPS (deployer) 我已经为我的AWS ec2 VPS创建了用户(部署程序)

When i am logging with: 当我登录时:

ssh -i ~/.ssh/aws/*...*.pem ubuntu@ec2*...*.amazonaws.com

command rvm use 2.0.0 is working correctly 命令rvm use 2.0.0正常工作

=> =>

    ubuntu@ip-***:~$ rvm list

    rvm rubies

    =* ruby-2.0.0-p247 [ x86_64 ]

    # => - current
    # =* - current && default
    #  * - default

    ubuntu@ip-***:~$ rvm which
    ubuntu@ip-***:~$ 

But when i use su - deployer i have got: 但是当我使用su-部署程序时,我得到了:

deployer@ip***:/home/ubuntu$ rvm
    The program 'rvm' is currently not installed. You can install it by typing:
    sudo apt-get install ruby-rvm

I would like to understand how correctly write command for ssh login. 我想了解如何正确编写ssh登录命令。 I have tried: 我努力了:

ssh -i ~/.ssh/aws/*.pem *ubuntu@ec2***.amazonaws.com -t 'bash --login -c "rvm"'

but received "Connection to ec2- * .amazonaws.com closed". 但收到“与ec2- * .amazonaws.com的连接已关闭”的信息。

Within my local machine rvm functioning correctly. 在我的本地计算机上,rvm正常运行。 I have added 我已经添加了

  [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* 

into my ~/.bash_profile 进入我的〜/ .bash_profile

I have spent 3-5 hours studying stackoverflow topics related to this issue, but still not understand what am i doing wrong. 我花了3-5个小时研究与此问题相关的stackoverflow主题,但仍然不明白我在做什么错。

Any help will be highly appreciated! 任何帮助将不胜感激! Thanks in advance! 提前致谢!

I've run into this problem before and there are 2 ways to solve it. 我之前遇到过这个问题,有2种解决方法。

The first way is to log in directly as the deployer user to the instance. 第一种方法是直接以部署者用户身份登录到实例。 This might mean having to create a ssh keypair (see ssh-keygen -t rsa). 这可能意味着必须创建一个ssh密钥对(请参阅ssh-keygen -t rsa)。 Then you can log in with ssh deployer@ec2.instance.address This way the rvm will be loaded directly to the deployed user's shell. 然后,您可以使用ssh deployer@ec2.instance.address登录。这样,rvm将直接加载到已部署用户的Shell中。

A second way is not to use the dash when su to the deployed user account. 第二种方法是在su部署的用户帐户时不使用破折号。

When you use the dash then you load your own bashrc vs that particular user's bashrc. 使用破折号时,您将加载自己的bashrc与该特定用户的bashrc。

So sudo su deployer 所以sudo su deployer

you nee to use: 您需要使用:

su - deployer

it will ensure you use login shell 它将确保您使用登录外壳

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM