ssh রিমোট bash কমান্ড লাইন থেকে কিন্তু ব্যাস স্ক্রিপ্ট থেকে কাজ করে না


0

(নোট: যদিও আমি আমার নিজের কয়েকটি প্রশ্নের উত্তর দিয়েছি, তবুও এই পোস্টের নীচে আমার কোনও উত্তর নেই।)

যখন আমি bash কমান্ড লাইন থেকে নিম্নোক্ত কমান্ড চালাতে এটি কাজ করে।

ssh -t -v my-rails-project@192.168.29.205 sudo /home/my-rails-project/x/pg_rsync_ralph07_to_ralph12_finish

এবং ssh verbose আউটপুট হয়:

OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.29.205 [192.168.29.205] port 22.
debug1: Connection established.
debug1: identity file /home/my-rails-project/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/my-rails-project/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/my-rails-project/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/my-rails-project/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/my-rails-project/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/my-rails-project/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/my-rails-project/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/my-rails-project/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.29.205:22 as 'my-rails-project'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:EnDsn2kFQgiA56e4B2UuvDr3ajTLlN7/15lxLItnjUQ
debug1: Host '192.168.29.205' is known and matches the ECDSA host key.
debug1: Found key in /home/my-rails-project/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/my-rails-project/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.29.205 ([192.168.29.205]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: sudo /home/my-rails-project/x/pg_rsync_ralph07_to_ralph12_finish

সঠিক একই লাইন একটি bash স্ক্রিপ্ট এবং আমি পেতে

OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.29.205 [192.168.29.205] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.29.205:22 as 'my-rails-project'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:EnDsn2kFQgiA56e4B2UuvDr3ajTLlN7/15lxLItnjUQ
debug1: Host '192.168.29.205' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

দুই আউটপুট লাইন এ বিভাজক (লিপি)

debug1: Found key in /root/.ssh/known_hosts:1

(কমান্ড লাইন)

debug1: Found key in /home/my-rails-project/.ssh/known_hosts:1

আমি জানি না যে বিবর্তন সমস্যাটি নির্দেশ করে।

তাই আমার প্রশ্ন হল:

কেন স্ক্রিপ্ট থেকে চলাকালীন ssh /root/.ssh/known_hosts দেখছেন এবং কমান্ড লাইন থেকে রান করার সময় /home/my-rails-project/.ssh/known_hosts দেখছেন?

অবিলম্বে আমার নিজের প্রশ্নের উত্তর:

আচ্ছা, আমি এটি লেখার সময় ডাইভারজেন্সটির উত্তর পরিষ্কার হয়ে গেল: আমি স্ক্রিপ্টটি চালাচ্ছিলাম

sudo myScript

তাই আমার আরও প্রশ্ন হল: আমি কীভাবে ssh কে /home/my-rails-project/.ssh/known_hosts পরিচিত_হস্টসের জন্য ব্যবহার করব?

অবিলম্বে উপরে আমার নিজের প্রশ্নের উত্তর

গবেষণা একটি বিট উত্তর আমাকে নেতৃত্বে https://stackoverflow.com/questions/10765946/ssh-use-known-hosts-other-than-home-ssh-known-hosts

তাই এখন আমার কমান্ড লাইন এখন দেখায়

ssh -o UserKnownHostsFile=/home/my-rails-project/.ssh/known_hosts -t -v my-rails-project@192.168.29.205 sudo /home/my-rails-project/x/pg_rsync_ralph07_to_ralph12_finish

যখন আমার সামনে সুডো না থাকে তখন আবারো উপরের কমান্ড লাইন কাজ করে। যখন আমি এটির সামনে একটি সুডো ব্যবহার করি তখন এটি ব্যর্থ হয়। Verbose আউটপুট হয়:

my-rails-project@my-rails-project:~$ sudo ssh -o UserKnownHostsFile=/home/my-rails-project/.ssh/known_hosts -t -v my-rails-project@192.168.29.205 sudo /home/my-rails-project/x/pg_rsync_ralph07_to_ralph12_finish
[sudo] password for my-rails-project: 
OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.29.205 [192.168.29.205] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.29.205:22 as 'my-rails-project'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:EnDsn2kFQgiA56e4B2UuvDr3ajTLlN7/15lxLItnjUQ
debug1: Host '192.168.29.205' is known and matches the ECDSA host key.
debug1: Found key in /home/my-rails-project/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
my-rails-project@my-rails-project:~$ 

এবং সুডো এবং অ-সুডো ক্রোবোজ আউটপুট কাছাকাছি শব্দের তালিকা শেষের কাছাকাছি ডুবে যায়

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
my-rails-project@my-rails-project:~$ 

প্রশ্ন:

আমার ব্যক্তিগত কী জন্য /root/.ssh এর পরিবর্তে /home/my-rails-project/.ssh ব্যবহার করার জন্য ssh কীভাবে বলব এবং এখনও টার্গেট সিস্টেমে সুডো করব?

অবিলম্বে আমার নিজের প্রশ্নের উত্তর:

দিকে তাকাও http://manpages.ubuntu.com/manpages/trusty/man1/ssh.1.html

সুতরাং এখন ssh কমান্ড লাইন (একটি -i বিকল্প)

ssh -o UserKnownHostsFile=/home/my-rails-project/.ssh/known_hosts -i /home/my-rails-project/.ssh/id_rsa -t -v my-rails-project@192.168.29.205 sudo /home/my-rails-project/x/pg_rsync_ralph07_to_ralph12_finish

এবং তারপর আমি কিছু (ssh?) ছাড়া একটি পাসওয়ার্ড জন্য জিজ্ঞাসা আছে সাফল্য আছে। আউটপুট এখন মনে হচ্ছে:

my-rails-project@my-rails-project:~$ sudo ssh -o UserKnownHostsFile=/home/my-rails-project/.ssh/known_hosts -i /home/my-rails-project/.ssh/id_rsa -t -v my-rails-project@192.168.29.205 sudo /home/my-rails-project/x/pg_rsync_ralph07_to_ralph12_finish
OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.29.205 [192.168.29.205] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /home/my-rails-project/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/my-rails-project/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.29.205:22 as 'my-rails-project'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:EnDsn2kFQgiA56e4B2UuvDr3ajTLlN7/15lxLItnjUQ
debug1: Host '192.168.29.205' is known and matches the ECDSA host key.
debug1: Found key in /home/my-rails-project/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/my-rails-project/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
Enter passphrase for key '/home/my-rails-project/.ssh/id_rsa': 
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.29.205 ([192.168.29.205]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: sudo /home/my-rails-project/x/pg_rsync_ralph07_to_ralph12_finish

প্রশ্ন:

আমি নিম্নলিখিত প্রম্পট পেতে:

Enter passphrase for key '/home/my-rails-project/.ssh/id_rsa': 

কিভাবে আমি পাসওয়ার্ডের জন্য এই অনুরোধটি দমন করব?

আমি আমার মেশিনে উভয় (Ralph07 এবং Ralph12) /etc/sudoers.d/ralph ম্যাসেজ করে পাসওয়ার্ডগুলির জন্য সর্বাধিক অনুরোধগুলিকে দমন করতে সক্ষম হয়েছে।

# This script should only be run on Ralph07
my-rails-project ALL=(ALL:ALL) NOPASSWD: /home/my-rails-project/x/pg_rsync_ralph07_to_ralph12

# This script should only be run on Ralph12
my-rails-project ALL=(ALL:ALL) NOPASSWD: /home/my-rails-project/x/pg_rsync_ralph07_to_ralph12_finish

উত্তর:


1

'কী'র জন্য পাসফ্রেজ লিখুন' প্রম্পট প্রদর্শিত হয় কারণ আপনার ssh কী পাসফ্রেজের মাধ্যমে তৈরি করা হয়েছিল।

আপনি নিম্নরুপে আপনার ssh কী থেকে পাসফ্রেজটি সরাতে পারেন:

ssh-keygen -p -N '' -f ~/my-rails-project/.ssh/id_rsa

অথবা আপনি একটি পাসফ্রেজ ছাড়া একটি নতুন কী তৈরি করতে পারেন:

ssh-keygen -q -t rsa -b 4096 -N '' -C '' -f ~/my-rails-project/.ssh/id_rsa

আপনি একটি চেহারা নিতে পারেন sshpass টুলটি ssh কমান্ডের জন্য পাসফ্রেজ সরবরাহ করতে ব্যবহার করা যেতে পারে তবে এটি কিছু নিরাপত্তা সমস্যা খোলার জন্য সুপারিশ করা হয় না।


1
কি শান্তি! ধন্যবাদ! আমি 15 + খ্যাতি পয়েন্ট ছিল ইচ্ছুক তাই আমি আপনার উত্তর ভোট দিতে পারে।
— RalphShnelvar
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.