Explore information related to sudo
sudo sorry you must have a tty to run sudo - Fix it now
This article covers how to resolve the error sudo: sorry you must have a tty to run sudo which happens because the sudo command tries to execute a command that requires a tty.
To fix "sudo: sorry, you must have a tty to run sudo" error:
You have to run your ssh command as follows to avoid error that read as sudo: Sorry, you must have a tty to run sudo Error:
ssh -t hostname sudo command
ssh -t user@hostname sudo command
ssh -t user@box.example.com sudo command1 /path/to/file
The -t option force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g., when implementing menu services.
Multiple -t options force tty allocation, even if ssh has no local tty.
The requiretty option in sudoers file
The requiretty if set in sudo config file sudoers, sudo will only run when the user is logged in to a real tty.
When this flag is set, sudo can only be run from a login session and not via other means such as cron, shell/perl/python or cgi-bin scripts.
This flag is set on many distores by default. Edit /etc/sudoers, file, enter:
# visudo
Find line that read as follows:
Defaults requiretty
Either comment it out the line or delete the line:
#Defaults requiretty
Save and close the file.
Ignore permission denied message from find command in Linux
This article covers how to resolve the error 'ignore permission denied message from find' which occurs while running a 'find' command in Linux.
The find command is used to locate files on a Linux or Unix like operating system.
The find command will search directory to match the supplied search criteria.
You can search for files by type, name, owner, group, date, permissions and more. By default the find will search all subdirectories for you.
Linux divides the file permissions into read, write and execute denoted by r,w, and x.
The permissions on a file can be changed by 'chmod' command which can be further divided into Absolute and Symbolic mode.
The 'chown' command can change the ownership of a file/directory.
If you prefer using the command line, you can easily find a file's permission settings with the ls command, used to list information about files/directories.
You can also add the –l option to the command to see the information in the long list format.
To change directory permissions in Linux, use the following:
1. chmod +rwx filename to add permissions.
2. chmod -rwx directoryname to remove permissions.
3. chmod +x filename to allow executable permissions.
4. chmod -wx filename to take out write and executable permissions.
Ansible error Shared connection to server closed
This article covers the Shared connection to server closed error which occur when we run an Ansible command to execute commands on two newly deployed CentOS 8 servers.
Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning.
While you can write Ansible modules in any language, most Ansible modules are written in Python, including the ones central to letting Ansible work. By default, Ansible assumes it can find a /usr/bin/python on your remote system that is either Python2, version 2.6 or higher or Python3, 3.5 or higher.
A quick fix to Ansible error Shared connection to server closed is to just add the path to python 3 in your inventory file.
It would look something like this:
ip_address ansible_python_interpreter=/usr/bin/python3
Then you could test if it works with the ping module:
ansible -m ping all
From the error details, the connection failed because the shell(s) in the remote system couldn't find the Python interpreter (/usr/bin/python) as indicated by the line: "module_stdout": "/bin/sh: /usr/bin/python: No such file or directory\r\n".
After checking the remote hosts, we discovered that the systems don't have Python 2 installed.
Check Python Binary
They have Python 3 installed by default and its binary is /usr/bin/python3.
According to the Ansible documentation, Ansible (2.5 and above) works with Python version 3 and above only.
Also, Ansible is supposed to automatically detect and use Python 3 on many platforms that ship with it.
However, if it fails to, then you can explicitly configure a Python 3 interpreter by setting the ansible_python_interpreter inventory variable at a group or host level to the location of a Python 3 interpreter.
Preserve Permissions in rsync
This article will guide you on how to use rsync to preserve permissions.
Rsync, or Remote #Sync, is a free command-line tool that lets you transfer files and directories to local and remote destinations. #Rsync is used for mirroring, performing backups, or migrating data to other servers.
a = archive - means it preserves #permissions (owners, groups), times, symbolic links, and devices. Use of "/" at the end of path: When using "/" at the end of source, rsync will copy the content of the last folder.
To preserve permissions when files and folders are copied or moved, use the Xcopy.exe utility with the /O or the /X switch.
The object's original permissions will be added to inheritable permissions in the new location.
To make rsync to preserve timestamps:
1. To overcome this, there is another option that you can specify in the rsync command that will preserve the timestamps during the synchronization process.
2. Without preserving the timestamp, the files will display the modification date and time as the time that the rsync command was run.
How Chmod 777 works
This article will guide you on how to give #Chmod 777 to folders and files in #Linux. We also discussed the risks and more information about file permissions.
If you are managing a Linux system, it is crucial to know how the Linux #permissions work.
You should never set 777 (rwxrwxrwx) permissions #files and #directories permissions. 777 means that anyone can do anything with those files.
To Give Root Privileges to a User in Linux:
1. Adding to Root Group using usermod. Let see how we can grant normal user root access by adding to root group.
2. Adding to #Root Group using Useradd Command.
3. Editing /etc/passwd file.
4. Setting as Sudo User.
Add User To Group in Linux
This article will guide you on how to add a #user to a #group in #Linux. The group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users. The others permissions apply to all other users on the system, this is the permission group that you want to watch the most.
Groups can be thought of as levels of #privilege. A person who is part of a group can view or modify files belonging to that group, depending on the permissions of that file. User belonging to a group has privileges of that group, for example - sudo groups lets you run software as super user.
To view all groups present on the system simply open the /etc/group file. Each line in this file represents information for one group. Another option is to use the getent command which displays entries from #databases configured in /etc/nsswitch.
To Create a New Sudo User:
1. Log in to your server as the root user. #ssh root@server_ip_address.
2. Use the adduser command to add a new user to your system. Be sure to replace username with the user that you want to create.
3. Use the usermod command to add the user to the wheel group.
4. Test sudo access on new user account.
To List Users in Linux:
i. Get a List of All Users using the /etc/passwd File.
ii. Get a List of all Users using the getent Command.
iii. Check whether a user exists in the Linux system.
iv. System and Normal Users.
Steps to Edit Sudoers File in Linux Process to get it done
This article will guide you on how to edit #Sudoers File in Linux which involves #root privileges, with a special focus on editing the /etc/sudoers file. You can configure who can use #sudo #commands by editing the /etc/sudoers file, or by adding configuration to the /etc/sudoers. To edit the sudoers file, we should always use the #visudo command. This uses your default editor to edit the sudoers configuration.
User is not in the sudoers file
Basically, when the wrong permission is assigned to the sudoers file, the error "user is not in the sudoers file" is usually triggered.
