Could not login with bash shell by default - ruby-on-rails

I want to run a Ruby on Rails application. When I tried to run it, it shows me this,
The program 'rails' is currently not installed. You can install it by typing:
sudo apt install ruby-railties
So, I figured out the problem and I found that the problem is due to not login into bash shell. My terminal could not execute 'ruby' or 'ruby on rails' scripts. I checked .bashrc and .bash_profile files if PATH variable is set to point to rvm file.
When I did,
/bash/bin -l
it shows me ruby or rails are installed on system and I could start Rails server successfully. But if I opened another Terminal window, same problem occurs. Basically, I want to log into bash shell by default. Please correct and help me to sort out this. Thanks!

If you are sure the location of your bash shell is /bin/bash you could use this command (replacing "username" with your username):
chsh -s /bin/bash username
That will change your default shell in most unix like operating systems.
Afterwards you can verify it checking /etc/passwd where you will see the default shell at the end of the line of your username.
Warning: Try it first with a new user, in order to avoid losing your shell access if the path to bash is different :-)

Related

How can I be denied access to a postgres directory even with sudo?

I need to get access to pg_hba.conf to try and fix my broken postgres development db that gives the error on RAILS_ENV=development rails s of
PG::ConnectionBad
fe_sendauth: no password supplied
This post at least seems to suggest that such access may help: PG::ConnectionBad: fe_sendauth: no password supplied
The problem is, even though I know the path
/Library/PostgreSQL/9.3/data/pg_hba.conf
When I actually try to cd into it:
cd /Library/PostgreSQL/9.3/data/
I get: cd:cd:13: permission denied: /Library/PostgreSQL/9.3/data/
The seemingly obvious fix would be to sudo, so I try that:
sudo cd /Library/PostgreSQL/9.3/data/
And nothing happens. Literally the next line shows that I'm still exactly where I was. How can sudo be denied? And how can I either access this file or fix my issue?
Thanks!
This:
sudo cd /Library/PostgreSQL/9.3/data/
runs the cd command under sudo. sudo actually runs a new instance of the shell (/bin/sh or whatever) then runs the command in the shell.
The current directory is a property of the current process. It is inherited by new child processes, but it changes do not get propagated up to parent processes.
What you've done is the equivalent of:
sh -c 'cd /tmp'
It makes a new shell, cds to a location, then exits. The effect of the cd only affects that shell, So it effectively did nothing.
What you should do instead is use sudo to open the file in your text editor by absolute path, e.g.:
sudo nano /Library/PostgreSQL/9.3/data/pg_hba.conf
(nano is a simple and user-friendly command line text editor; I'm assuming you don't know how to use vi given this question.)

rails s command does not run from ssh

I am using Putty to connect to my localhost, and I don't have any problems apparently, however, when I run command rails s to start my rails 4.0.0 application from Putty, it gives me this message:
jose#jose-laptop:~/rails/dedicated-agenda$ rails s
The program 'rails' can be found in the following packages:
ruby-railties-3.2
ruby-railties-4.0
Try: sudo apt-get install
I don't get that message from the terminal though, the application starts running just fine.
I had to reinstall ubuntu so I upgraded to ubuntu 14.04 just in case you need to know.
I don't know if I am missing something in my ssh settings or how could I use rails s from Putty.
Thanks in advance.
Your PATH environment variable is set differently when you are executing programs in an interactive shell and by ssh(using putty).
Use absolute path of the program to not depend on the PATH variable.
You can also set the right PATH variable at ~/.profile file and load the updated variables using the command source ~/.profile.
Now, you should be able to run the command.
You can use the command
>which rails
to see where rails is installed on your working session.
Then you need to make sure that is in your path when you ssh in.
If you are ssh'ing in as a different use then that user may not have permission to see the rails executable.

Unable to run ruby script over ssh into ec2 instance

I'm working with ec2 instances and was trying to execute a ruby script on another instance after ssh to that instance.
I have a ruby script which updates configuration files, so i need to run that script as super user. when i run the script manually on that instance, sudo ruby recreate-532d01c.rb, the error that comes is
sudo: ruby: command not found
Running simple scripts with no root permissions works, eg.ruby file_1.rb.
Using rvmsudo in place of sudo executes the script with warning,
ubuntu#ip-10-0-0-111:~$ rvmsudo ruby recreate-82bb000012.rb
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:
export rvmsudo_secure_path=1
to avoid the warning, put it in shell initialization file to make it persistent.
In case there is no `secure_path` in `/etc/sudoers`. Run:
export rvmsudo_secure_path=0
to avoid the warning, put it in shell initialization file to make it persistent.
I tried to execute the below command from rails console of one of the instance to test and it fails to recognize ruby as command
1.9.3-p545 :002 > system("ssh -i /home/ubuntu/.ssh/own_key.pem ubuntu#**.***.***.** ruby execute-52d.rb")
bash: ruby: command not found
I tried with possible solutions over web, but could not resolve the issue. I have the same configuration running for one of my old aws acount, this is a newly created account. Not sure if this could be issue in any way as currently ec2 instances fall under vpc by default and have some changes after dec 2013
Nothing to do with your VPC. So when you run your ruby script with sudo your environment that your user is using doesn't get set for Ruby.
Sounds like you may be using rvm and you probably set it up with a 'single user' config.
Try running as your user:
which ruby
and see where your ruby executable is located at. That's what you have to make sure that when your run your script as sudo it's available in the PATH.
Worst case you would have to reinstall rvm with multiuser config which should work when you run with sudo:
user$ \curl -sSL https://get.rvm.io | sudo bash -s stable

Automatically Run Command Upon Opening Terminal (Linux Mint 16)

I am using Rails and for some reason unbeknownst to me I have to execute the following line every time I start the terminal in order to use ruby and rails.
source ~/.bash_profile
If I type the following before running the above command, it will recommend that I install the packages (ie "type 'sudo apt-get install package' to install")
rails -v && ruby -v && irb -v
Is there a way to make my terminal execute a command upon opening? Or, better yet, can anybody help explain the reason I have to run this line? I found an article that said I had to do that given my issue but it didn't explain why.
Assuming you're using the bash shell, then ~/.bash_profile will be sourced once (and only once) when you log in to the system but not each time you open a terminal window.
The ~/.bashrc, however, will be sourced every time a new shell is opened (i.e. when you open a terminal window).
So they are probably some environment variables settings in ~/.bash_profile which are required for ruby to run. Those settings should be moved to the ~/.bashrc file instead so they are defined in all shell instances.
Alternatively, source ~/.bash_profile from your ~/.bashrc (this is at your own risk, it may have side-effects).

can not run sudo in a rails resque worker

I have a resque worker which will run some shell command.
for example
ruby
`sudo echo "XXX" >> xx.log`
but when worker run, will raise below error
sudo: no tty present and no askpass program specified
I have add 'whoami' debug code to find which user run this sudo command,
and also set this user's group "test" when execute command will don't need password.
I'm also run same command in shell console, it works right, don't need input password.
sudo visudo
%test ALL=NOPASSWD:ALL
but when the worker run sudo, will says above error, require input password.
Who can tell me why?
Thanks.
I am really hesitant to offer this as a "fix" because #AJcodez asks correctly, "why do you need sudo?" However, you can probably get around the tty requirement by adding the following:
Defaults requiretty
Defaults: %test !requiretty
to the /etc/sudoers file, but please use the visudo command. Also, is test here a user or a group? I also suspect that your sudoers line is malformed. The syntax is:
jane ALL=(LIST_OF_COMMANDS) NOPASSWD: ALL
Where you seem to have it set to run the NOPASSWD setting for all zero commands the %test group can run. Or I could be misunderstanding your paste here.

Resources