![]() You can use the printenv command to see all the environment variables for user2, and then set them in the script using the export command. So you can use the command sudo -n -i -u user2 /usr/local/bin/script.sh to run the script as user2 with their environment variables set, without being prompted for a password.Īnother solution would be to set the needed environment variables in the script itself, by using the export command. One solution would be to use the sudo -n option, which allows you to run a command with elevated privileges without being prompted for a password. To run the script as user2 with their environment variables set, you can use the sudo -i -u user2 command, but this prompts for a password. Again, let me say DO NOT allow remote remote log-ins to your root account.You are correct that the issue is that the environment variables for user2 are not set when running the script with sudo -u user2. If you really want to allow remote connections directly to the root account, you need to enable the root account (see my comment below). My above answer does not answer the original poster's actual question, it describes what you should do instead. You are trying to set sudo to not ask for your password, which is not recommended, but you can learn how to do that via an answer like This happens whether you are connected remotely (via passwordless or password-protected SSH) or are local on the machine. This does require the user to type their password. Sudo is used to permit a normal user account to do something with super user permissions. If you can ssh and connect without a password, this is set up correctly, and has nothing else to do with this. Passwordless log is used to make sure that people can't log into your system remotely by guessing your password. Of the two, I suggest allowing as few commands as possible (first answer) rather then all commands (second answer). How to run sudo command with no password?.How do I run specific sudo commands without a password?.You configure sudo to allow you to run commands without a password. ssh -i ~/.ssh/foo 2 : Running commands via sudo without entering a password You should now be able to ssh in with your key without a password and you should not be able to ssh in as any user without a key. On the server : sudo passwd -l rootĮdit /etc/ssh/sshd_config sudo nano `/etc/ssh/sshd_config`Ĭhange the following : PasswordAuthentication no Test the key ssh -i ~/.ssh/foo it works, unset a root password and disable password login. Set a root password, use a strong one sudo passwdįrom the client, Transfer the key to the server ssh-copy-id -i ~/.ssh/foo "foo" the the name of your key and enter your server root password when asked. Restart the server sudo service ssh restart Make sure you allow root to log in with the following syntax PasswordAuthentication yes On the server (where you ssh TO)Įdit /etc/ssh/sshd_config sudo nano /etc/ssh/sshd_config ![]() ![]() To do this you must temporarily allow root to ssh into the server. Next you need to transfer the key to the server. When you are prompted for a password, just hit the enter key and you will generate a key with no password. ![]() The -f option specifies a file name, foo is an example, use whatever name you wish. I highly suggest you give it a name rather then using the default ssh-keygen -f foo On the client (where you ssh FROM)įirst make a ssh key with no password. If you do not have root access on the server, contact the server administrator for help. One way or another you need root access on the server to do this. Easiest method is to temporarily allow root to log in over ssh via password. To set up a passwordless SSH connection for the root user you need to have root access on the server. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |