Plink + sudo in emacs: connection without password - ssh

I would like to modify a file on a remote server with emacs on a user I can only access through sudo su - username without a password.
I am currently able to modify files on my personal space on this server using:
C-x C-f /plink:me#server:/path/file
I read there that I could use the following to open a file as the other user:
C-x C-f /plink:me#server|sudo:other#server:/path/file
The problem is that using this syntax, emacs asks me for a password Password for /sudo:other#server: which I don't have.. giving an empty password does not work, neither does giving my user's password.
Is there a way to configure tramp to connect to this other user as sudo su - other would do without asking for a password?
PS: I am using emacs 28.1 on Windows 10.

You could specify a new Tramp method, derived from the sudo method:
(add-to-list 'tramp-methods
`("mysudo"
(tramp-login-program "sudo")
(tramp-login-args (("su") ("-" "%u")))
(tramp-remote-shell ,tramp-default-remote-shell)
(tramp-remote-shell-login ("-l"))
(tramp-remote-shell-args ("-c"))
(tramp-connection-timeout 10)
(tramp-session-timeout 300)))
Then you can open a remote file like
C-x C-f /plink:me#server|mysudo:other#server:/path/file
Disclaimer: it is untested.

Related

Edit file as other user on other host in Emacs

I've seen this but my situation is slightly different. Currently I edit the file like this:
ssh HOST_1
ssh HOST_2
su OTHER_USER
vim ~/FILENAME
How do I tell Emacs (using tramp) to edit this file, while including the hop from HOST_1 to HOST_2 as well as the su OTHER_USER?
"multi-hop" with "me" as the user works fine:
/sshx:HOST_1|sshx:HOST_2:/user/me/FILENAME
However, adding sudo su OTHER_USER fails:
/sshx:HOST_1|sshx:HOST_2|sudo:OTHER_USER#HOST_2:
After typing the final colon, I am prompted for a password. After entering the password, I can type the remote file path, but it appears to be an empty filesystem somewhere, with no folders or files at all.
The *Messages* buffer contains this:
Tramp: Encoding local file ‘/tmp/tramp.61Eexc.ulUhgA’ using ‘base64-encode-region’...done
Tramp: Decoding remote file ‘/ssh:HOST_2:/tmp/tramp.ulUhgA’ using ‘base64 -d -i >%s’...done
I've replicated this on my preferred Emacs setup (using sshx with spacemacs 0.200.13, Emacs 26.3) as well as a completely vanilla Emacs 25.2.2 (using ssh).

SSH from Synology NAS to remote server

When I run competitions for Icelandic Horses, I want to automatically upload the results from our Synology NAS to a remote webserver. The program we use automatically generates the html-files that needs to be uploaded.
What is the easiest way to achieve this? I have SSH access on both the NAS and the webserver.
Any help is appreciated :)
In this case you can create a cron task in the synology console with the command:
sudo -i
vi /etc/crontab
Edit the file and add a line like this at the end of the file with a scp command:
0 0 * * * root scp -r "-i/root/.ssh/mykey" 'root#serverurl.com:/some/remote/path' '/some/local/path'
Finally you have to reload the configuration restarting the service with:
synoservice -restart crond
Before all this you must to configure a pair keys to avoid the password entry:
cd to a private directory of the user which will be running the script (typically "$HOME/.ssh", to be created if needed). That directory must be protected to write acces from other users, fix the modes if needed.
generate the keypair using command "ssh-keygen"
("/usr/syno/bin/ssh-keygen" if not in your PATH)
at the prompt "Enter file in which to save the key", choose a file
name (let's say "mykey")
at the prompt "Enter passphrase (empty for no passphrase):" press
return (this will create a passwordless private key)
Two files will be created: "mykey" and "mykey.pub"
copy the contents of mykey.pub inside "$HOME/.ssh/authorized_key"
file of user account on the remote machine your script is going to
connect to.
in your script, add "-i" as argument to the
ssh command
Also in this forum is explained how to make the copy with rsync instead of scp

PUTTY access Denied

I am trying to login using putty SSH it showing error "Access Denied Using Keyboard-interactive authentication.", I am trying with correct id and password.
My solution found.
I'd try:
1- SSH Config Reset http://YOURIPADDRESS:2086/scripts2/doautofixer?autofix=safesshrestart
2- Host Access Control add sshd ip allow
3- Manage root’s SSH Keys key creat and putty connect
4- Cpanel any domain login -> create ssh key > putty login su root
5- WHM Service Manager sshd enabled
6- Other root username login test
But not login.
SOLUTION:
any domain ssh connect via key -> vim /etc/passwd or vi /etc/passwd
/etc/passwd (preview):
root:x:0:0:root:/root:/bin/bash^M
bin:x:1:1:bin:/bin:/sbin/nologin^M
...
PROBLEM = ^M
Contact system administration clear ^M char solved.
Note: Because I have already edited the passwd file in the "windows" environment. Do not edit windows editor.
For edit: Putty another login and su root -> vim /etc/passwd -> clear all ^M -> For Save :wq, For Not save quit :q!
EDIT
If that does not work try using the command line:
putty.exe -l [LOGIN] -pw [PASSWORD] [HOST]
---END EDIT---
Try unchecking the encircled checkbox.
Maybe you are logging in as a user that is blocked (this error can happen if trying to login as root).
If you need to be a blocked user, try logging in as another user then after you are successfully logged in,
Run Command :
su amit
or
su root
as the case may be.
Instead of editing /etc/passwd utilizing vim to remove the ^M you can just install dos2unix to fix that issue.
sudo apt install dos2unix -y
sudo dos2unix /etc/passwd
The ^M typically happens when someone edits the Linux file in a Windows text editor and then saves that file back to a Linux system. The Linux system picks up on the end of line character placed by Windows and see's it as a ^M

finding out sudo password on ssh server

I need to do a sudo command on a ssh server.
It asks for password
[sudo] password for myname:
but it's apparently different from the password for ssh server itself.
Can sudo only be used by root?
If not, should I ask the maintenance people for the password?
Or is there a way to set it up myself?
See : http://www.gratisoft.us/sudo/sudoers.man.html
Specifically see rootpw, targetpw , etc.
It is possible to have two different passwords, one for the account and another for the sudo command.
You should ask to the Maintenance people....

plink ssh as root, access denied

I'm trying to connect to a server via plink. However, I'm getting the following error:
C:\>plink -ssh -pw password root#server-name
Using username "root".
Access denied
My sshd_config file contains PermitRootLogin yes, even though that's the default value, just to be sure. Is there some other configuration I need to set to allow this type of connection?
Please post or check contents of the log probably found at /var/log/auth.log.
Another question would be if you have a password added for your root account?
Otherwise you can try and set this using sudo passwd root.
My password contained special characters (!##$%^). I needed to add double-quotes around them to get it to not complain. Silly me!