Prevent user from changing directory using rbash - bash

I have created two new users in my FreeBSD unix environment and I want to limit their access to their respective home directories only.
After reading on the internet, I found a solution to modify /etc/passwd file and change their bash to rbash which will prevent them to run CD command.
so I run the following command to find where my rbash is ?
where rbash
and it gives the following output,
usr/local/bin/rbash
so I opened my /etc/passwd file and change the /bin/sh to /usr/local/bin/rbash.
After that I logged out and logged back in using the account for which I modified the settings but I could still run the CD command, or any other command for that matter.
Can anyone please tell me why it is not working ?
Can this be done using Samba or any other solution ?

Related

Batch script permissions issues

I have a batch script written to auto start and capture traffic on a server for me but for some reason when I run it wireshark tells me it doesn't have permission to the folder where the script is trying to save the file. I have tried multiple different folders on and off the server I have tried giving everyone including SYSTEM full access to the folder. I have tried remaking the folder. I have tried running under and not under admin credentials I have tried letting the system task run it. Always get a permissions issue.
The weirdest part is if I run wireshark manually and save the data manually it has no permissions issues. Just if I run the script is the problem. Although they're both run under the same admin account.
Here is the script in case you need to see the flags I used.
#echo off
cd C:\Program Files\Wireshark
Wireshark.exe -i 4 -k -a duration:10 -w C:\Temp
pause
I did try to use a powershell script I had found online but it was pretty old and I couldn't get it to actually run. So any recommendations are welcome that include powershell or batch
C:\Temp isn't a file; it's a folder. Try specifying an actual filename, like this:
#echo off
cd C:\Program Files\Wireshark
Wireshark.exe -i 4 -k -a duration:10 -w C:\Temp\foo.pcapng
pause

Visual Studio Code always asks for sudo permissions

Ok, so I've got a problem with VSCode where every time I try to save a file it asks me for sudo permission and it's really annoying and I can't make folders or files directly in the IDE. Can please someone help me?
Screenshot from VSCode
The running instance of VS Code doesn't seem to have write permission to the file you wish to save.
Since the file is in the directory of user uteu3, first make sure that it is user uteu3 that has started VS Code (it probably is, if uteu3 is the user logged into the system).
make sure uteu3 is the owner of the file and change the permissions by opening a terminal and executing:
sudo chown uteu3 filename && sudo chmod 664 filename
(Replace filename with actual path+name to the file.)
If this doesn't solve the problem, please execute the following two lines in a terminal and provide the output:
ps aux | grep visual-studio-code
stat -f '%A %a %N' filename
Since you indicate that this happens repeatedly also with other files, maybe several of the file permissions in your home directory are problematic. In that case, consider trying to fix them all. See for example: Need to fix file permissions in a user's home directory
.

Download zip file from s3 using s3cmd issue

I have two issues I need help with on bash, linux and s3cmd.
First, I'm running into linux permission issue. I am trying to download zip files from a s3 bucket using s3cmd with following command in a bash script.sh:
/usr/bin/s3cmd get s3://<bucketname>/<folder>/zipfilename.tar.gz
I am seeing following error: permission denied.
If I try to run this command manually from command line on a linux machine, it works and downloads the file:
sudo /usr/bin/s3cmd get s3://<bucketname>/<folder>/zipfilename.tar.gz
I really don't want to use sudo in front of the command in the script. How do I get this command to work? Do I need to give chown permission to the script.sh which is actually sitting in a path i.e /foldername/script.sh or how do I get this get command to work?
Two: Once I get this command to work, How do I get it to download from s3 to the linux home dir: ~/ ? Do I have to specifically issue a command in the bash script: cd ~/ before the above download command?
I really appreciate any help and guidance.
First, determine what's failing and the reason, otherwise you won't find the answer.
You can specify the destination in order to avoid permission problems when the script is invoked using a directory that's not writeable by that process
/usr/bin/s3cmd get s3:////zipfilename.tar.gz /path/to/writeable/destination/zipfilename.tar.gz
Fist of all ask 1 question at a time.
For the first one you can simply change the permission with chown like :
chown “usertorunscript” filename
For the second :
If it is users home directory you can just specify it with
~user
as you said but I think writing the whole directory is safer so it will work for more users (if you need to)

Change Owner of a script in unix

I have a unix shell script file whose owner is "xyz" when run deletes some specific files.
I want to trigger this script to delete files in some other directory where the owner for the files to be deleted is different from the owner of the script. Is this possible? Is this possible to run this script as different user so that it can delete those new files?
EDIT : I use Autosys to periodically trigger this script.
You can chmod the files that need to be deleted first if you have sufficient rights. Afterwards your script, no matter what user it executes, will succeed.
Examples : http://en.wikipedia.org/wiki/Chmod
Usually you use sudo for that:
sudo -u ANOTHER_USER /path/to/the/script.sh
However, your current account needs proper permissions to do so. You can configure those permissions using the file /etc/sudoers.
You'll find a ton of articles out there how to use sudo. This for example: http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:Ch09:_Linux_Users_and_Sudo

How do I run .sh or .bat files from Terminal?

I have a pretty basic problem here, that has happened so haphazardly to me that up until now, I've just ignored it. I downloaded tomcat web server and "Murach's Java Servlets and JSP" book is telling me to navigate to the tomcat/bin directory and start the server my typing in Terminal
$ startup
However, I get the error
-bash: startup: command not found
The relevant files in this directory are startup.sh and startup.bat. Typing both of these returns the same error message
So my questions are, what are .bat and sh files, and how do I run these files? I've read several tutorials for different languages and software programs, and some times when the tutorial says execute a bunch of files in the command line, I get a "command not found" error. Sometimes it works, sometimes it doesn't. This is perplexing to me, so what are some common solutions to solving these sort of "command not found" Terminal problems?
The .sh is for *nix systems and .bat should be for Windows. Since your example shows a bash error and you mention Terminal, I'm assuming it's OS X you're using.
In this case you should go to the folder and type:
./startup.sh
./ just means that you should call the script located in the current directory. (Alternatively, just type the full path of the startup.sh). If it doesn't work then, check if startup.sh has execute permissions.
This is because the script is not in your $PATH. Use
./scriptname
You can also copy this to one of the folders in your $PATH or alter the $PATH variable so you can always use just the script name. Take care, however, there is a reason why your current folder is not in $PATH. It might be a security risk.
If you still have problems executing the script, you might want to check its permissions - you must have execute permissions to execute it, obviously. Use
chmod u+x scriptname
A .sh file is a Unix shell script. A .bat file is a Windows batch file.
Type bash script_name.sh or ./script_name in linux terminal. Before using ./script_name make you script executeable by sudo chmod 700 script_name and type script_name.bat in windows.
Drag-And-Drop
Easiest way for a lazy Mac user like me: Drag-and-drop the startup.sh file from the Finder to the Terminal window and press Return.
To shutdown Tomcat, do the same with shutdown.sh.
You can delete all the .bat files as they are only for a Windows PC, of no use on a Mac to other Unix computer. I delete them as it makes it easier to read that folder's listing.
File Permissions
I find that a fresh Tomcat download will not run on my Mac because of file permission restrictions throwing errors during startup. I use the BatChmod app which wraps a GUI around the equivelant Unix commands to reset file permissions.
Port-Forwarding
Unix systems protect access to ports numbered under 1024. So if you want to use port 80 with Tomcat you will need to learn how to do "port-forwarding" to forward incoming requests to port 8080 where Tomcat listens by default. To do port-forwarding, you issue commands to the packet-filtering (firewall) app built into Mac OS X (and BSD). In the old days we used ipfw. In Mac OS X 10.7 (Lion) and later Apple is moving to a newer tool, pf.
Based on IsmailS' comment the command which worked for me on OSX was:
sudo sh ./startup.sh
On windows type either startup or startup.bat
On unix type ./startup.sh
(assuming you are located in tomcat/bin directory)
Batch files can be run on Linux. This article explains how (http://www.linux.org/threads/running-windows-batch-files-on-linux.7610/).
Type in
chmod 755 scriptname.sh
In other words, give yourself permission to run the file. I'm guessing you only have r/w permission on it.
add #!bin/bash on top of the your .sh file
sudo chmod +x your .sh file
./your.sh file
these steps work~
My suggestion does not come from Terminal; however, this is a much easier way.
For .bat files, you can run them through Wine. Use this video to help you install it: https://www.youtube.com/watch?v=DkS8i_blVCA. This video will explain how to install, setup and use Wine. It is as simple as opening the .bat file in Wine itself, and it will run just as it would on Windows.
Through this, you can also run .exe files, as well .sh files.
This is much simpler than trying to work out all kinds of terminal code.
I had this problem for *.sh files in Yosemite and couldn't figure out what the correct path is for a folder on my Desktop...after some gnashing of teeth, dragged the file itself into the Terminal window; hey presto!!

Resources