Visit Our UNIX and Linux User Community

Unable to edit file remotely using ssh

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to edit file remotely using ssh
# 1  
Old 09-03-2013
Unable to edit file remotely using ssh


I am trying to edit the /etc/sudoers file using ksh, however I am unable to do that. Please find the code below:

ssh $i "/usr/local/bin/sudo /usr/bin/echo "$user_id     ALL=(ALL) ALL" >> /etc/sudoers"

I've tried changing the double quotes to single but it is still not working. The user_id will be given when the script runs. I've tried this also:

ssh $i '/usr/local/bin/sudo /usr/bin/echo "$user_id     ALL=(ALL) ALL" >> /etc/sudoers'

I am getting the below error in both the cases:

ksh: /etc/sudoers: cannot create

Any suggestions will be appreciated.

# 2  
Old 09-03-2013
Looks to be a permission issue with your credentials on the remote machine. Are you sure the userid thats used with ssh login is part of sudoers on the remote machine ?

Also pls check permissions of /etc/sudoers on the remote system.
# 3  
Old 09-03-2013
The user which is executing the script is added into the sudoers of the remote machine also the permissions of the sudoers file are given below:

# grep -i testmgmt /etc/sudoers
testmgmt        ALL=(ALL) NOPASSWD: /usr/sbin/useradd, /usr/sbin/userdel, /usr/local/bin/sudo, /usr/sam/lbin/usermod.sam, /usr/bin/perl, /log/script/server_script/, /log/script/server_script/, /usr/bin/echo
# ls -ld /etc/sudoers
-r--r-----   1 root       root          1928 Sep  3 14:39 /etc/sudoers

Please suggest now, as the user is able to create the users on the remote machine but unable to edit the sudoers file.
# 4  
Old 09-03-2013
The safest way to edit sudoers file without changing its permissions is using visudo

This thread will give you some hint

linux - How do I edit /etc/sudoers from a script? - Stack Overflow

Previous Thread | Next Thread
Test Your Knowledge in Computers #68
Difficulty: Easy
Awk is abbreviated from the names of the developers - Aho, Weinberger, and Kernighan.
True or False?

10 More Discussions You Might Find Interesting

1. Solaris

How to remotely start ssh on Solaris?

Hi everyone, I have a Solaris machine: SunOS 5.10 Generic_127127-11 sun4v sparc SUNW,SPARC-Enterprise-T5220 After reboot, I can't ssh to this machine. Error message: ssh: connect to host xxxx port 22: Connection refused It seems ssh daemon is not running, but I don't have... (5 Replies)
Discussion started by: Zaiwen Gong
5 Replies

2. HP-UX

Unable to edit the sudoers file using script

Hi All, I've made a script in order to delete the users. The script is deleting the users and removing its entry from the /etc/sudoers however it is changing the permissions of the /etc/sudoers file to the user from which it is executing the script. #!/bin/ksh #set -x print "The script... (2 Replies)
Discussion started by: Kits
2 Replies

3. Solaris

SSH Remotely

Hello. I am trying to ssh and run a script from a remote computer. These computers will be both Windows and MACs. I am using Solaris 8 and what I have tried is: using putty ssh user@ip_address (remote command) /folder/folder/ The issue here is that the user profile has not... (3 Replies)
Discussion started by: jkmtm
3 Replies

4. Red Hat

Cant Access Applicatoin GUI Remotely (SSH)

Greetings! Theres an application in my RHEL 6 server that has a GUI (which we'd like to use). When I run the is says it needs Server X11. I know its gotta do something with X server (and I installed it).I found some tutorial for auto configuration and then I was supposed to access... (0 Replies)
Discussion started by: RedSpyder
0 Replies

5. Shell Programming and Scripting

ssh execute command remotely

Hi all, Today I want to write a script to run the commands remotely. If I run the command as follows: ssh <user>@<ip> 'ls; pwd' it works fine. But when I want to use ssh to set view in clearcase, it will lose the response. as follows ssh <user>@<ip> 'cleartool setview <view_name>; pwd'... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

6. Shell Programming and Scripting

remotely append crontab over ssh

Hi I would like to append/modify crontab remotely over ssh and this is what i have tried so far. text.txt contains the following line. 0,15,30,45 * * * * /home/local/ cat text.txt |ssh $host 'tee' but i dont know how to edit the crontab here after piping it to tee command. (2 Replies)
Discussion started by: xiamin
2 Replies

7. Shell Programming and Scripting

chown remotely via ssh / invalid group

Hi, i have a problem with a shell script. I need to change the owner and group of a file on a remote machine. I tried to use ssh but have some problems. The code: group=`ssh -t -t $1 -p 3344 "stat -c %G $cpath/FILE"` echo " $2:$group " echo $1 echo $cpath ssh $1 -p 3344 "chown... (5 Replies)
Discussion started by: Linien
5 Replies

8. UNIX for Advanced & Expert Users

connecting windows remotely from unix using SSH

Hi Can someone giv me some knowledge on accesing windows from unix and executing DOS scripts using SSH I would like to know how to go abt new to it. Thanks in advance (1 Reply)
Discussion started by: lakshmis10
1 Replies

9. UNIX for Advanced & Expert Users

using ssh change password remotely?

Is it possible to change the password using a shell script, I want to remotely connect to a computer and then change password without manual intevention. Thanks in Advance Rishi (4 Replies)
Discussion started by: RishiPahuja
4 Replies

10. Shell Programming and Scripting

Not able to remotely connect to server using ssh

Hi, I am trying to run the below command in perl but when the perl script is executed it prompts a error message saying " ssh: <username>: Name or service not known ". Not able to understand this as this command runs perfectly on the server prompt. ` ssh <username>@pus4026dev df -k >>... (2 Replies)
Discussion started by: be2sp1
2 Replies

Featured Tech Videos