Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [root@ol4 ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- centos_v1 default 8269dafdd9f8 2 weeks ago 196.7 MB
- nginx latest e43d811ce2f4 3 weeks ago 181.4 MB
- centos 7 980e0e4c79ec 9 weeks ago 196.7 MB
- centos latest 980e0e4c79ec 9 weeks ago 196.7 MB
- [root@ol4 ~]# clear
- [root@ol4 ~]# python
- Python 2.7.5 (default, Sep 14 2016, 08:35:31)
- [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> cmd1='hostname'
- >>> cmd2='docker images'
- >>> srvr='rhel1'
- >>> srvr1='ol4'
- >>> ssh=paramiko.SSHClient()
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- NameError: name 'paramiko' is not defined
- >>> import paramiko
- >>> ssh=paramiko.SSHClient()
- >>> ssh.set_missing_host_key_policy(paraniko.AutoAddPolicy())
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- NameError: name 'paraniko' is not defined
- >>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- >>> ssh.connect(srvr,username='root')
- >>> stdin,stdout,stderr=ssh.exec_command(cmd1)
- >>> stdout
- <paramiko.ChannelFile from <paramiko.Channel 0 (closed) -> <paramiko.Transport at 0x2a17c50L (cipher aes128-ctr, 128 bits) (active; 0 open channel(s))>>>
- >>> stdout.readlines()
- [u'rhel1\n']
- >>> stderr.readlines()
- []
- >>> cmd3='hotname'
- >>> ssh.close()
- >>> ssh=paramiko.SSHClient()
- >>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- >>> ssh.connect(srvr,username='root')
- >>> stdin,stdout,stderr=ssh.exec_command(cmd3)
- >>> stdout.readlines()
- []
- >>> stderr.readlines()
- [u'bash: hotname: command not found\n']
- >>> ssh.close()
- >>> ssh=paramiko.SSHClient()
- >>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- >>> ssh.connect(srvr1,username='root')
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 380, in connect
- look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
- File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 603, in _auth
- raise saved_exception
- paramiko.ssh_exception.AuthenticationException: Authentication failed.
- >>> srvr1
- 'ol4'
- >>> ssh.connect(srvr1,username='root')
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 380, in connect
- look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
- File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 603, in _auth
- raise saved_exception
- paramiko.ssh_exception.AuthenticationException: Authentication failed.
- >>> exit()
- [root@ol4 ~]# ssh ol4
- root@ol4's password:
- Last login: Sat Nov 12 19:29:34 2016 from rhel1
- [root@ol4 ~]# exit
- logout
- Connection to ol4 closed.
- [root@ol4 ~]# pwd
- /root
- [root@ol4 ~]# ssh
- ssh ssh-agent sshd ssh-keygen
- ssh-add ssh-copy-id sshd-keygen ssh-keyscan
- [root@ol4 ~]# ssh
- ssh ssh-agent sshd ssh-keygen
- ssh-add ssh-copy-id sshd-keygen ssh-keyscan
- [root@ol4 ~]# ssh-copy-id root@ol4
- /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
- /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
- root@ol4's password:
- Number of key(s) added: 1
- Now try logging into the machine, with: "ssh 'root@ol4'"
- and check to make sure that only the key(s) you wanted were added.
- [root@ol4 ~]# exit
- logout
- Connection to ol4 closed.
- [root@rhel1 ~]# ssh ol4
- Last login: Sat Nov 12 19:34:38 2016 from ol4
- [root@ol4 ~]# ssh root@ol4
- Last login: Sat Nov 12 19:34:59 2016 from rhel1
- [root@ol4 ~]# exit
- logout
- Connection to ol4 closed.
- [root@ol4 ~]# python
- Python 2.7.5 (default, Sep 14 2016, 08:35:31)
- [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import paramiko
- >>> cmd='docker images'
- >>> srvr1='ol4'
- >>> ssh=paramiko.SSHClient()
- >>> ssh.set_missing_host_key_policy(paraniko.AutoAddPolicy())
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- NameError: name 'paraniko' is not defined
- >>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- >>> ssh.connect(srvr1,username='root')
- >>> stdin,stdout,stderr=ssh.exec_command(cmd)
- >>> stdout.readlines()
- [u'REPOSITORY TAG IMAGE ID CREATED SIZE\n', u'centos_v1 default 8269dafdd9f8 2 weeks ago 196.7 MB\n', u'nginx latest e43d811ce2f4 3 weeks ago 181.4 MB\n', u'centos 7 980e0e4c79ec 9 weeks ago 196.7 MB\n', u'centos latest 980e0e4c79ec 9 weeks ago 196.7 MB\n']
- >>> a=stdout.readlines()
- >>> for item in a:
- ... print item
- ...
- >>> a
- []
- >>> ssh.close()
- >>> ssh=paramiko.SSHClient()
- >>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- >>> ssh.connect(srvr1,username='root')
- >>> stdin,stdout,stderr=ssh.exec_command(cmd)
- >>> a=stdout.readlines()
- >>> a
- [u'REPOSITORY TAG IMAGE ID CREATED SIZE\n', u'centos_v1 default 8269dafdd9f8 2 weeks ago 196.7 MB\n', u'nginx latest e43d811ce2f4 3 weeks ago 181.4 MB\n', u'centos 7 980e0e4c79ec 9 weeks ago 196.7 MB\n', u'centos latest 980e0e4c79ec 9 weeks ago 196.7 MB\n']
- >>> for line in a:
- ... print line
- ...
- REPOSITORY TAG IMAGE ID CREATED SIZE
- centos_v1 default 8269dafdd9f8 2 weeks ago 196.7 MB
- nginx latest e43d811ce2f4 3 weeks ago 181.4 MB
- centos 7 980e0e4c79ec 9 weeks ago 196.7 MB
- centos latest 980e0e4c79ec 9 weeks ago 196.7 MB
- >>> stderr.readlines()
- []
- >>> ssh.close()
- >>> print cmd
- docker images
Add Comment
Please, Sign In to add comment