|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: HOWTO Obtain new Openshift token from Xterm |
| 4 | +date: 2025-02-14 09:15:16 |
| 5 | +description: OpenShift login token expired because tokens are, by default, valid for a limited time (e.g., 24 hours). Follow these steps to obtain a new token and continue working with the cluster. |
| 6 | +tags: OpenShift token xterm CLI text-web-browser lynx |
| 7 | +categories: OpenShift |
| 8 | +--- |
| 9 | + |
| 10 | +# How to Obtain a New Token for OpenShift from xterm |
| 11 | + |
| 12 | +OpenShift login tokens expire because they are, by default, valid for a limited time (e.g., 24 hours). One way to obtain a new token is by SSHing into the controller machine and |
| 13 | +running the [relogin.sh script](https://github.com/dsariel/scripts/blob/master/OpenShift/relogin.sh). See the content below: |
| 14 | + |
| 15 | + |
| 16 | +# OpenShift Token Refresh |
| 17 | + |
| 18 | +OpenShift login tokens expire because they are, by default, valid for a limited time (e.g., 24 hours). One way to obtain a new token is by SSHing into the controller machine and running the relogin.sh script. |
| 19 | + |
| 20 | +<iframe src="https://github.com/dsariel/scripts/blob/master/OpenShift/relogin.sh" width="100%" height="400px"></iframe> |
| 21 | + |
| 22 | +# ------------------------------ |
| 23 | + |
| 24 | +# OpenShift Token Refresh |
| 25 | + |
| 26 | +OpenShift login tokens expire because they are, by default, valid for a limited time (e.g., 24 hours). One way to obtain a new token is by SSHing into the controller machine and running the relogin.sh script. |
| 27 | + |
| 28 | +<div id="script-content"></div> |
| 29 | +<script> |
| 30 | +fetch('https://raw.githubusercontent.com/dsariel/scripts/master/OpenShift/relogin.sh') |
| 31 | + .then(response => response.text()) |
| 32 | + .then(data => { |
| 33 | + document.getElementById('script-content').innerHTML = '<pre><code>' + data + '</code></pre>'; |
| 34 | + }); |
| 35 | +</script> |
| 36 | + |
| 37 | +# ------------------------------ |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +```bash |
| 42 | +<!-- Embed script from raw GitHub content --> |
| 43 | +curl -s https://raw.githubusercontent.com/dsariel/scripts/master/OpenShift/relogin.sh | cat |
| 44 | + |
| 45 | +``` |
| 46 | + |
| 47 | +and using a text-based web browser on the remote server if connecting via the web console is not an option. Follow these steps to obtain a new token and continue working with the cluster: |
| 48 | + |
| 49 | +## Steps to Obtain a New Token |
| 50 | + |
| 51 | +1. **Install a Text-Based Browser**\ |
| 52 | + Install `lynx`, a command-line browser, to access the token request page: |
| 53 | + |
| 54 | + ```bash |
| 55 | + sudo yum install lynx -y |
| 56 | + ``` |
| 57 | + |
| 58 | +2. **Retrieve a password for the `kubeadmin` user**\ |
| 59 | + If you are using the default `kubeadmin` user, retrieve the password from the installation directory: |
| 60 | + |
| 61 | + ```bash |
| 62 | + cat ~/.kube/kubeadmin-password |
| 63 | + ``` |
| 64 | + |
| 65 | + Use this password to log in as `kubeadmin` in the browser interface during the next stage. |
| 66 | + |
| 67 | +3. **Access the Token Request Page**\ |
| 68 | + Use `lynx` to navigate to the token request page: |
| 69 | + |
| 70 | + ```bash |
| 71 | + lynx https://oauth-openshift.apps.ocp.openstack.lab/oauth/token/request |
| 72 | + ``` |
| 73 | + |
| 74 | +4. **Obtain a New Token**\ |
| 75 | + Once logged in, obtain a new token. The login command will look like this: |
| 76 | + |
| 77 | + ```bash |
| 78 | + oc login --token=sha256~<...> --server=https://api.ocp.openstack.lab:6443 |
| 79 | + ``` |
| 80 | + |
| 81 | + |
| 82 | + |
0 commit comments